node-pg-migrate
Advanced tools
Comparing version 4.8.0 to 5.0.0
# Change Log | ||
## [5.0.0](2020-05-19) | ||
### Breaking changes | ||
- remove node 8 support [#615](https://github.com/salsita/node-pg-migrate/pull/615) | ||
- Ability to use sort of UTC time in filename [#622](https://github.com/salsita/node-pg-migrate/pull/622) | ||
If you used a different format for migrations names than the default one it can potentially break the order of your migrations | ||
- Migration can be also symlink [#630](https://github.com/salsita/node-pg-migrate/pull/630) | ||
If you have symlinks in the migration folder, migration can potentially break | ||
### Fixed | ||
- Fixed position of TEMPORARY clause in create table [#629](https://github.com/salsita/node-pg-migrate/pull/629) | ||
## [4.8.0](2020-05-04) | ||
@@ -4,0 +21,0 @@ |
@@ -11,3 +11,3 @@ import { ClientBase, ClientConfig, QueryArrayConfig, QueryConfig } from 'pg'; | ||
} | ||
declare const db: (connection: string | ClientConfig | ClientBase, logger?: Logger) => DBConnection; | ||
declare const db: (connection: ClientBase | string | ClientConfig, logger?: Logger) => DBConnection; | ||
export default db; |
@@ -6,9 +6,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PgType = exports.Migration = exports.PgLiteral = exports.default = void 0; | ||
const runner_1 = __importDefault(require("./runner")); | ||
exports.default = runner_1.default; | ||
const migration_1 = require("./migration"); | ||
exports.Migration = migration_1.Migration; | ||
Object.defineProperty(exports, "Migration", { enumerable: true, get: function () { return migration_1.Migration; } }); | ||
const types_1 = require("./types"); | ||
exports.PgType = types_1.PgType; | ||
Object.defineProperty(exports, "PgType", { enumerable: true, get: function () { return types_1.PgType; } }); | ||
const PgLiteral_1 = __importDefault(require("./operations/PgLiteral")); | ||
exports.PgLiteral = PgLiteral_1.default; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
@@ -8,0 +20,0 @@ }; |
@@ -6,2 +6,3 @@ import { DBConnection } from './db'; | ||
export declare const loadMigrationFiles: (dir: string, ignorePattern?: string | undefined) => Promise<string[]>; | ||
export declare const getTimestamp: (logger: Logger, filename: string) => number; | ||
export interface RunMigration { | ||
@@ -12,4 +13,8 @@ readonly path: string; | ||
} | ||
export declare enum FilenameFormat { | ||
timestamp = "timestamp", | ||
utc = "utc" | ||
} | ||
export declare class Migration implements RunMigration { | ||
static create(name: string, directory: string, language?: 'js' | 'ts' | 'sql', ignorePattern?: string): Promise<string>; | ||
static create(name: string, directory: string, language?: 'js' | 'ts' | 'sql', ignorePattern?: string, filenameFormat?: FilenameFormat): Promise<string>; | ||
readonly db: DBConnection; | ||
@@ -16,0 +21,0 @@ readonly path: string; |
@@ -6,17 +6,14 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Migration = exports.FilenameFormat = exports.getTimestamp = exports.loadMigrationFiles = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const mkdirp_1 = __importDefault(require("mkdirp")); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = require("util"); | ||
const migration_builder_1 = __importDefault(require("./migration-builder")); | ||
const utils_1 = require("./utils"); | ||
const readdir = util_1.promisify(fs_1.default.readdir); | ||
const lstat = util_1.promisify(fs_1.default.lstat); | ||
const { readdir } = fs_1.default.promises; | ||
const SEPARATOR = '_'; | ||
exports.loadMigrationFiles = async (dir, ignorePattern) => { | ||
const dirContent = await readdir(`${dir}/`); | ||
const files = (await Promise.all(dirContent.map(async (file) => { | ||
const stats = await lstat(`${dir}/${file}`); | ||
return stats.isFile() ? file : null; | ||
}))) | ||
const dirContent = await readdir(`${dir}/`, { withFileTypes: true }); | ||
const files = dirContent | ||
.map((file) => (file.isFile() || file.isSymbolicLink() ? file.name : null)) | ||
.filter((file) => Boolean(file)) | ||
@@ -36,2 +33,27 @@ .sort(); | ||
}; | ||
exports.getTimestamp = (logger, filename) => { | ||
const prefix = filename.split(SEPARATOR)[0]; | ||
if (prefix && /^\d+$/.test(prefix)) { | ||
if (prefix.length === 13) { | ||
return Number(prefix); | ||
} | ||
if (prefix && prefix.length === 17) { | ||
const year = prefix.substr(0, 4); | ||
const month = prefix.substr(4, 2); | ||
const date = prefix.substr(6, 2); | ||
const hours = prefix.substr(8, 2); | ||
const minutes = prefix.substr(10, 2); | ||
const seconds = prefix.substr(12, 2); | ||
const ms = prefix.substr(14); | ||
return new Date(`${year}-${month}-${date}T${hours}:${minutes}:${seconds}.${ms}Z`).valueOf(); | ||
} | ||
} | ||
logger.error(`Can't determine timestamp for ${prefix}`); | ||
return Number(prefix) || 0; | ||
}; | ||
var FilenameFormat; | ||
(function (FilenameFormat) { | ||
FilenameFormat["timestamp"] = "timestamp"; | ||
FilenameFormat["utc"] = "utc"; | ||
})(FilenameFormat = exports.FilenameFormat || (exports.FilenameFormat = {})); | ||
class Migration { | ||
@@ -42,3 +64,3 @@ constructor(db, migrationPath, { up, down }, options, typeShorthands, logger = console) { | ||
this.name = path_1.default.basename(migrationPath, path_1.default.extname(migrationPath)); | ||
this.timestamp = Number(this.name.split(SEPARATOR)[0]) || 0; | ||
this.timestamp = exports.getTimestamp(logger, this.name); | ||
this.up = up; | ||
@@ -50,6 +72,8 @@ this.down = down; | ||
} | ||
static async create(name, directory, language, ignorePattern) { | ||
static async create(name, directory, language, ignorePattern, filenameFormat = FilenameFormat.timestamp) { | ||
mkdirp_1.default.sync(directory); | ||
const suffix = language || (await getLastSuffix(directory, ignorePattern)) || 'js'; | ||
const newFile = `${directory}/${Date.now()}${SEPARATOR}${name}.${suffix}`; | ||
const now = new Date(); | ||
const time = filenameFormat === FilenameFormat.utc ? now.toISOString().replace(/[^\d]/g, '') : now.valueOf(); | ||
const newFile = `${directory}/${time}${SEPARATOR}${name}.${suffix}`; | ||
await new Promise((resolve, reject) => { | ||
@@ -56,0 +80,0 @@ fs_1.default.createReadStream(path_1.default.resolve(__dirname, `../templates/migration-template.${suffix}`)) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameDomain = exports.alterDomain = exports.createDomain = exports.dropDomain = void 0; | ||
const utils_1 = require("../utils"); | ||
@@ -4,0 +5,0 @@ function dropDomain(mOptions) { |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createExtension = exports.dropExtension = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
@@ -8,0 +9,0 @@ function dropExtension(mOptions) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameFunction = exports.createFunction = exports.dropFunction = void 0; | ||
const utils_1 = require("../utils"); | ||
@@ -4,0 +5,0 @@ function dropFunction(mOptions) { |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createIndex = exports.dropIndex = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
@@ -8,0 +9,0 @@ function generateIndexName(table, columns, options) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameOperatorClass = exports.createOperatorClass = exports.dropOperatorClass = exports.renameOperatorFamily = exports.addToOperatorFamily = exports.removeFromOperatorFamily = exports.createOperatorFamily = exports.dropOperatorFamily = exports.createOperator = exports.dropOperator = void 0; | ||
const utils_1 = require("../utils"); | ||
@@ -4,0 +5,0 @@ function dropOperator(mOptions) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sql = void 0; | ||
const utils_1 = require("../utils"); | ||
@@ -4,0 +5,0 @@ function sql(mOptions) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renamePolicy = exports.alterPolicy = exports.createPolicy = exports.dropPolicy = void 0; | ||
const makeClauses = ({ role, using, check }) => { | ||
@@ -4,0 +5,0 @@ const roles = (Array.isArray(role) ? role : [role]).join(', '); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameRole = exports.alterRole = exports.createRole = exports.dropRole = void 0; | ||
const lodash_1 = require("lodash"); | ||
@@ -4,0 +5,0 @@ const utils_1 = require("../utils"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameSchema = exports.createSchema = exports.dropSchema = void 0; | ||
function dropSchema(mOptions) { | ||
@@ -4,0 +5,0 @@ const _drop = (schemaName, options = {}) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameSequence = exports.alterSequence = exports.createSequence = exports.dropSequence = exports.parseSequenceOptions = void 0; | ||
const utils_1 = require("../utils"); | ||
@@ -4,0 +5,0 @@ exports.parseSequenceOptions = (typeShorthands, options) => { |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addConstraint = exports.dropConstraint = exports.renameConstraint = exports.renameColumn = exports.renameTable = exports.alterColumn = exports.addColumns = exports.dropColumns = exports.alterTable = exports.createTable = exports.dropTable = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
@@ -194,3 +195,3 @@ const utils_1 = require("../utils"); | ||
const tableNameStr = mOptions.literal(tableName); | ||
const createTableQuery = `CREATE TABLE${temporaryStr}${ifNotExistsStr} ${tableNameStr} ( | ||
const createTableQuery = `CREATE${temporaryStr} TABLE${ifNotExistsStr} ${tableNameStr} ( | ||
${utils_1.formatLines(tableDefinition)} | ||
@@ -197,0 +198,0 @@ )${inheritsStr};`; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameTrigger = exports.createTrigger = exports.dropTrigger = void 0; | ||
const lodash_1 = require("lodash"); | ||
@@ -4,0 +5,0 @@ const utils_1 = require("../utils"); |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameTypeValue = exports.renameTypeAttribute = exports.renameType = exports.addTypeValue = exports.setTypeAttribute = exports.addTypeAttribute = exports.dropTypeAttribute = exports.createType = exports.dropType = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
@@ -8,0 +9,0 @@ const utils_1 = require("../utils"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renameView = exports.alterViewColumn = exports.alterView = exports.createView = exports.dropView = void 0; | ||
const utils_1 = require("../utils"); | ||
@@ -4,0 +5,0 @@ function dropView(mOptions) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.refreshMaterializedView = exports.renameMaterializedViewColumn = exports.renameMaterializedView = exports.alterMaterializedView = exports.createMaterializedView = exports.dropMaterializedView = void 0; | ||
const utils_1 = require("../utils"); | ||
@@ -4,0 +5,0 @@ const dataClause = (data) => (data !== undefined ? ` WITH${data ? '' : ' NO'} DATA` : ''); |
@@ -19,3 +19,3 @@ "use strict"; | ||
const files = await migration_1.loadMigrationFiles(options.dir, options.ignorePattern); | ||
return Promise.all(files.map(async (file) => { | ||
return (await Promise.all(files.map(async (file) => { | ||
const filePath = `${options.dir}/${file}`; | ||
@@ -28,3 +28,3 @@ const actions = path_1.default.extname(filePath) === '.sql' | ||
return new migration_1.Migration(db, filePath, actions, options, Object.assign({}, shorthands), logger); | ||
})); | ||
}))).sort((m1, m2) => m1.timestamp - m2.timestamp); | ||
} | ||
@@ -31,0 +31,0 @@ catch (err) { |
@@ -6,5 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getActions = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const util_1 = require("util"); | ||
const readFile = util_1.promisify(fs_1.default.readFile); | ||
const { readFile } = fs_1.default.promises; | ||
const createMigrationCommentRegex = (direction) => new RegExp(`^\\s*--[\\s-]*${direction}\\s+migration`, 'im'); | ||
@@ -11,0 +11,0 @@ exports.getActions = (content) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PgType = void 0; | ||
var PgType; | ||
@@ -4,0 +5,0 @@ (function (PgType) { |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatLines = exports.makeComment = exports.formatParams = exports.applyType = exports.applyTypeAdapters = exports.getMigrationTableSchema = exports.getSchemas = exports.escapeValue = exports.createTransformer = exports.createSchemalize = void 0; | ||
const decamelize_1 = __importDefault(require("decamelize")); | ||
@@ -8,0 +9,0 @@ const PgLiteral_1 = __importDefault(require("./operations/PgLiteral")); |
{ | ||
"name": "node-pg-migrate", | ||
"version": "4.8.0", | ||
"version": "5.0.0", | ||
"description": "Postgresql database migration management tool for node.js", | ||
@@ -34,3 +34,3 @@ "author": "Theo Ephraim", | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"node": ">=10.0.0" | ||
}, | ||
@@ -55,10 +55,10 @@ "bugs": { | ||
"@types/chai-as-promised": "7.1.2", | ||
"@types/lodash": "4.14.150", | ||
"@types/lodash": "4.14.151", | ||
"@types/mkdirp": "1.0.0", | ||
"@types/mocha": "7.0.2", | ||
"@types/proxyquire": "1.3.28", | ||
"@types/sinon": "9.0.0", | ||
"@types/sinon": "9.0.1", | ||
"@types/sinon-chai": "3.2.4", | ||
"@typescript-eslint/eslint-plugin": "2.30.0", | ||
"@typescript-eslint/parser": "2.30.0", | ||
"@typescript-eslint/eslint-plugin": "2.33.0", | ||
"@typescript-eslint/parser": "2.33.0", | ||
"chai": "4.2.0", | ||
@@ -70,3 +70,3 @@ "chai-as-promised": "7.1.1", | ||
"dotenv": "8.2.0", | ||
"eslint": "6.8.0", | ||
"eslint": "7.0.0", | ||
"eslint-config-airbnb-base": "14.1.0", | ||
@@ -82,3 +82,3 @@ "eslint-config-prettier": "6.11.0", | ||
"mocha": "7.1.2", | ||
"pg": "8.0.3", | ||
"pg": "8.2.1", | ||
"prettier": "2.0.5", | ||
@@ -90,3 +90,3 @@ "proxyquire": "2.1.3", | ||
"ts-node": "8.10.1", | ||
"typescript": "3.8.3" | ||
"typescript": "3.9.2" | ||
}, | ||
@@ -93,0 +93,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
278795
3349