@vbilopav/pgmigrations
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -39,6 +39,6 @@ const crypto = require('crypto'); | ||
historyTableName: "schema_history", | ||
historyTableSchema: "public", | ||
historyTableSchema: "pgmigrations", | ||
skipPattern: "scrap", | ||
useProceduralScript: false, | ||
warnOnInvalidPrefix: false, | ||
warnOnInvalidPrefix: true, | ||
parseScriptTags: true, | ||
@@ -51,4 +51,5 @@ | ||
}, | ||
sortFunction: (a, b) => a.localeCompare(b, "en"), | ||
versionSortFunction: (a, b) => a.localeCompare(b, "en", {numeric: true}), | ||
sortByPath: true, | ||
sortFunction: (a, b, config) => config.sortByPath ? a.script.localeCompare(b.script, "en") : a.name.localeCompare(b.name, "en"), | ||
versionSortFunction: (a, b, config) => a.version.localeCompare(b.version, "en", {numeric: true}), | ||
@@ -55,0 +56,0 @@ testFunctionsSchemaSimilarTo: "test", |
@@ -92,4 +92,28 @@ const path = require("path"); | ||
function validateConfig(config) { | ||
var mandatory = [ | ||
"upPrefix","downPrefix","repetablePrefix","repetableBeforePrefix", | ||
"beforePrefix","afterPrefix","separatorPrefix", | ||
"historyTableName","historyTableSchema", | ||
"tmpDir","hashFunction" | ||
]; | ||
for (let i = 0; i < mandatory.length; i++) { | ||
const key = mandatory[i]; | ||
if (!config[key]) { | ||
error(`Config key ${key} is required. Please provide a valid config key.`); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
module.exports = { | ||
history: async function(opt, config) { | ||
if (!validateConfig(config)) { | ||
return; | ||
} | ||
var schemaQuery = str => formatByName(str, {schema: config.historyTableSchema, name: config.historyTableName}); | ||
@@ -105,15 +129,6 @@ | ||
migrate: async function(cmd, opt, config) { | ||
var mandatory = [ | ||
"upPrefix","downPrefix","repetablePrefix","repetableBeforePrefix", | ||
"beforePrefix","afterPrefix","separatorPrefix", | ||
"historyTableName","historyTableSchema", | ||
"tmpDir","hashFunction" | ||
]; | ||
for (let i = 0; i < mandatory.length; i++) { | ||
const key = mandatory[i]; | ||
if (!config[key]) { | ||
error(`Config key ${key} is required. Please provide a valid config key.`); | ||
return; | ||
} | ||
if (!validateConfig(config)) { | ||
return; | ||
} | ||
if (Array.isArray(config.migrationDir)) { | ||
@@ -447,10 +462,10 @@ for (let i = 0; i < config.migrationDir.length; i++) { | ||
afterList.sort((a, b) => config.sortFunction(a.name, b.name)); | ||
beforeList.sort((a, b) => config.sortFunction(a.name, b.name)); | ||
afterList.sort((a, b) => config.sortFunction(a, b, config)); | ||
beforeList.sort((a, b) => config.sortFunction(a, b, config)); | ||
repetableList.sort((a, b) => config.sortFunction(a.name, b.name)); | ||
repetableBeforeList.sort((a, b) => config.sortFunction(a.name, b.name)); | ||
repetableList.sort((a, b) => config.sortFunction(a, b, config)); | ||
repetableBeforeList.sort((a, b) => config.sortFunction(a, b, config)); | ||
upList.sort((a, b) => config.versionSortFunction(a.version, b.version)); | ||
downList.sort((a, b) => config.versionSortFunction(b.version, a.version)); | ||
upList.sort((a, b) => config.versionSortFunction(a, b, config)); | ||
downList.sort((a, b) => config.versionSortFunction(b, a, config)); | ||
@@ -457,0 +472,0 @@ if (opt.list) { |
{ | ||
"name": "@vbilopav/pgmigrations", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "PostgreSQL Migration Tool for Node.js and NPM", | ||
@@ -5,0 +5,0 @@ "author": "vb-consulting", |
@@ -336,3 +336,3 @@ # PgMigrations | ||
Schema name for the history table. If this schema doesn't exist, it will be created. The default is `public`. | ||
Schema name for the history table. If this schema doesn't exist, it will be created. The default is `pgmigrations`. | ||
@@ -363,12 +363,18 @@ #### historyTableName | ||
#### sortByPath | ||
Default: `true`. | ||
Sorts non-versioned migrations by path and then by name for migrations in multiple directories. | ||
#### sortFunction | ||
Default sort function used for sorting migration names. The default value is `(a, b) => a.localeCompare(b, "en")`. | ||
Default sort function used for sorting migration names. The default value is `sortFunction: (a, b, config) => config.sortByPath ? a.script.localeCompare(b.script, "en") : a.name.localeCompare(b.name, "en")`. | ||
#### versionSortFunction | ||
Default sort function used for sorting migration versions. The default value is `(a, b) => a.localeCompare(b, "en", {numeric: true})`. | ||
Default sort function used for sorting migration versions. The default value is `versionSortFunction: (a, b, config) => a.version.localeCompare(b.version, "en", {numeric: true})`. | ||
#### warnOnInvalidPrefix: false | ||
#### warnOnInvalidPrefix: true | ||
@@ -375,0 +381,0 @@ Display warning if some migration file with the migration extension (`.sql`) doesn't have a valid prefix. This may be just some script file that can be referenced with `# script` tag. The default is false. |
75665
1336
474