@vbilopav/pgmigrations
Advanced tools
Comparing version 0.23.0 to 0.24.0
@@ -41,2 +41,5 @@ const crypto = require('crypto'); | ||
dirsOrderReversed: false, | ||
appendTopDirToVersion: false, | ||
appendTopDirToVersionSplitBy: "__", | ||
appendTopDirToVersionPart: 0, | ||
keepMigrationDirHistory: false, | ||
@@ -43,0 +46,0 @@ tmpDir: path.join(os.tmpdir(), "___pgmigrations"), |
@@ -341,3 +341,30 @@ const path = require("path"); | ||
let version = null; | ||
let name = suffix.split(".").slice(0, -1).join(".").replace(/[^a-zA-Z0-9]/g, " ").trim().replace(/\s+/g, " "); | ||
const script = ((hasMultipleDirs ? (migrationDir + "/" + fileName).replace(/\\/g, "/") : fileName).replace(/\/+/g, "/")).replace('./', ""); | ||
if (prefix.startsWith(config.upPrefix) || prefix.startsWith(config.downPrefix)) { | ||
version = prefix.slice(config.upPrefix.length).trim(); | ||
if (config.migrationDir && config.appendTopDirToVersion) { | ||
const dirs = migrationDir.replace(/\\/g, "/").split("/"); | ||
const topDir = dirs[dirs.length - 1]; | ||
//const parts = topDir.split(config.appendTopDirToVersionSplitBy); | ||
//console.log(topDir); | ||
if (topDir) { | ||
if (config.appendTopDirToVersionSplitBy) { | ||
//version = topDir + version; | ||
const topDirSplit = topDir.split(config.appendTopDirToVersionSplitBy); | ||
const part = topDirSplit[config.appendTopDirToVersionPart]; | ||
if (part) { | ||
version = part + version; | ||
} | ||
} | ||
else { | ||
version = topDir + version; | ||
} | ||
} | ||
} | ||
name = version + " " + name; | ||
} | ||
if (usedNames[name]) { | ||
@@ -363,3 +390,2 @@ let dirParts = migrationDir.replace(/[^a-zA-Z0-9]/g, " ").trim().split(" "); | ||
let version = null; | ||
let type = null; | ||
@@ -371,3 +397,2 @@ const meta = {}; | ||
const hash = config.hashFunction(content); | ||
const script = ((hasMultipleDirs ? (migrationDir + "/" + fileName).replace(/\\/g, "/") : fileName).replace(/\/+/g, "/")).replace('./', ""); | ||
@@ -378,3 +403,2 @@ let pushTo = null; | ||
if (isUp) { | ||
version = prefix.slice(config.upPrefix.length).trim(); | ||
if (upVersions[version]) { | ||
@@ -409,3 +433,2 @@ error(`Migration file ${script} contains duplicate version ${version} already present in ${upVersions[version]}. Exiting...`); | ||
if (isDown) { | ||
version = prefix.slice(config.downPrefix.length).trim(); | ||
if (downVersions[version]) { | ||
@@ -412,0 +435,0 @@ error(`Migration file ${script} contains duplicate version ${version} already present in ${downVersions[version]}. Exiting...`); |
{ | ||
"name": "@vbilopav/pgmigrations", | ||
"version": "0.23.0", | ||
"version": "0.24.0", | ||
"description": "PostgreSQL Migration Tool for Node.js and NPM", | ||
@@ -5,0 +5,0 @@ "author": "vb-consulting", |
@@ -32,3 +32,3 @@ #!/usr/bin/env node | ||
error("Unknown config key: " + key +". Please provide a valid config key."); | ||
return; | ||
return {}; | ||
} | ||
@@ -63,3 +63,3 @@ mainConfig[key] = config[key]; | ||
return mainConfig; | ||
return mainConfig || {}; | ||
} | ||
@@ -66,0 +66,0 @@ |
@@ -322,3 +322,2 @@ # PgMigrations | ||
#### migrationExtensions: [".sql"], | ||
@@ -358,2 +357,22 @@ | ||
#### appendTopDirToVersion | ||
If `migrationDir` is true and versioned migration - add the top level directory name to version number, | ||
Default is false. | ||
#### appendTopDirToVersionSplitBy | ||
If `migrationDir` is true and versioned migration: | ||
split the top level directory name by this string and the index `appendTopDirToVersionPart` to version number. | ||
Default is "__". | ||
#### appendTopDirToVersionPart | ||
If `migrationDir` is true and versioned migration: | ||
split the top level directory name by this string and the index `appendTopDirToVersionPart` to version number. | ||
Default is 0. | ||
#### tmpDir | ||
@@ -360,0 +379,0 @@ |
84455
1490
538