@ovotech/pg-sql-migrate
Advanced tools
Comparing version 3.3.4 to 4.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const migrate_1 = require("./commands/migrate"); | ||
migrate_1.migrate().parse(process.argv); | ||
(0, migrate_1.migrate)().parse(process.argv); | ||
//# sourceMappingURL=cli.js.map |
@@ -15,5 +15,5 @@ "use strict"; | ||
.action(async (name, content, { config, configDirectory }) => { | ||
const { directory } = migrate_1.loadConfig(config, process.env, { directory: configDirectory }); | ||
const { directory } = (0, migrate_1.loadConfig)(config, process.env, { directory: configDirectory }); | ||
const file = `${new Date().toISOString()}_${name}.pgsql`; | ||
fs_1.writeFileSync(path_1.join(directory, file), content || ''); | ||
(0, fs_1.writeFileSync)((0, path_1.join)(directory, file), content || ''); | ||
logger.info(`Created ${file}`); | ||
@@ -20,0 +20,0 @@ }); |
@@ -15,4 +15,4 @@ "use strict"; | ||
.action(async ({ config, configDirectory, configTable, configClient, dryRun, }) => { | ||
await migrate_1.migrate({ | ||
config: migrate_1.loadConfig(config, process.env, { | ||
await (0, migrate_1.migrate)({ | ||
config: (0, migrate_1.loadConfig)(config, process.env, { | ||
client: configClient, | ||
@@ -19,0 +19,0 @@ directory: configDirectory, |
@@ -24,5 +24,5 @@ "use strict"; | ||
`) | ||
.addCommand(migrate_create_1.migrateCreate(logger)) | ||
.addCommand(migrate_execute_1.migrateExecute(logger), { isDefault: true }); | ||
.addCommand((0, migrate_create_1.migrateCreate)(logger)) | ||
.addCommand((0, migrate_execute_1.migrateExecute)(logger), { isDefault: true }); | ||
exports.migrate = migrate; | ||
//# sourceMappingURL=migrate.js.map |
@@ -15,8 +15,8 @@ "use strict"; | ||
exports.filenameParts = filenameParts; | ||
const readMigrations = ({ directory, executedIds = [], }) => fs_1.readdirSync(directory) | ||
const readMigrations = ({ directory, executedIds = [], }) => (0, fs_1.readdirSync)(directory) | ||
.filter((file) => file.endsWith('.pgsql')) | ||
.map((file) => exports.filenameParts(file)) | ||
.map((file) => (0, exports.filenameParts)(file)) | ||
.filter(({ id }) => !executedIds.includes(id)) | ||
.map(({ filename, id, name }) => { | ||
const content = fs_1.readFileSync(path_1.join(directory, filename)).toString(); | ||
const content = (0, fs_1.readFileSync)((0, path_1.join)(directory, filename)).toString(); | ||
return { id, name, content }; | ||
@@ -38,3 +38,3 @@ }); | ||
logger.info(`Executing [${migration.id}] ${migration.name}`); | ||
if (!exports.isTransactionDisabled(migration.content)) { | ||
if (!(0, exports.isTransactionDisabled)(migration.content)) { | ||
await db.query('BEGIN'); | ||
@@ -44,3 +44,3 @@ } | ||
await db.query(`INSERT INTO ${db.escapeIdentifier(table)} VALUES ($1);`, [migration.id]); | ||
if (!exports.isTransactionDisabled(migration.content)) { | ||
if (!(0, exports.isTransactionDisabled)(migration.content)) { | ||
await db.query('COMMIT'); | ||
@@ -51,3 +51,3 @@ } | ||
try { | ||
if (!exports.isTransactionDisabled(migration.content)) { | ||
if (!(0, exports.isTransactionDisabled)(migration.content)) { | ||
await db.query('ROLLBACK'); | ||
@@ -57,3 +57,3 @@ } | ||
finally { | ||
throw new _1.MigrationError(error.message, migration); | ||
throw new _1.MigrationError(String(error), migration); | ||
} | ||
@@ -65,4 +65,4 @@ } | ||
const readNewMigrations = async ({ db, table, directory, }) => { | ||
const executedIds = await exports.readExecutedIds({ db, table }); | ||
return exports.readMigrations({ directory, executedIds }); | ||
const executedIds = await (0, exports.readExecutedIds)({ db, table }); | ||
return (0, exports.readMigrations)({ directory, executedIds }); | ||
}; | ||
@@ -72,4 +72,4 @@ exports.readNewMigrations = readNewMigrations; | ||
if (client !== undefined) { | ||
const loadConfig = fs_1.existsSync(file) | ||
? config_file_1.loadConfigFile({ file, env, defaults: types_1.CONFIG_DEFAULTS, required: ['client'] }) | ||
const loadConfig = (0, fs_1.existsSync)(file) | ||
? (0, config_file_1.loadConfigFile)({ file, env, defaults: types_1.CONFIG_DEFAULTS, required: ['client'] }) | ||
: types_1.CONFIG_DEFAULTS; | ||
@@ -83,3 +83,3 @@ return { | ||
else { | ||
return config_file_1.loadConfigFile({ file, env, defaults: types_1.CONFIG_DEFAULTS, required: ['client'] }); | ||
return (0, config_file_1.loadConfigFile)({ file, env, defaults: types_1.CONFIG_DEFAULTS, required: ['client'] }); | ||
} | ||
@@ -90,3 +90,3 @@ }; | ||
try { | ||
const migrations = await exports.readNewMigrations({ db, table, directory }); | ||
const migrations = await (0, exports.readNewMigrations)({ db, table, directory }); | ||
logger.info(migrations.length | ||
@@ -96,3 +96,3 @@ ? `Executing ${migrations.length} new migrations` | ||
if (!dryRun) { | ||
await exports.executeMigrations({ db, table, migrations, logger }); | ||
await (0, exports.executeMigrations)({ db, table, migrations, logger }); | ||
} | ||
@@ -110,3 +110,3 @@ logger.info(`Successfully executed ${migrations.length} new migrations`); | ||
const migrate = async ({ config, env = process.env, logger = console, dryRun = false, } = {}) => { | ||
const { client, table, directory } = typeof config === 'object' ? { ...types_1.CONFIG_DEFAULTS, ...config } : exports.loadConfig(config, env); | ||
const { client, table, directory } = typeof config === 'object' ? { ...types_1.CONFIG_DEFAULTS, ...config } : (0, exports.loadConfig)(config, env); | ||
const db = new pg_1.Client(client); | ||
@@ -122,3 +122,3 @@ await db.connect(); | ||
try { | ||
await exports.readAndExecuteMigrations({ db, table, directory, logger, dryRun }); | ||
await (0, exports.readAndExecuteMigrations)({ db, table, directory, logger, dryRun }); | ||
} | ||
@@ -125,0 +125,0 @@ finally { |
@@ -6,5 +6,6 @@ { | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], | ||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "tsx", "json", "node"], | ||
"testURL": "http://localhost/", | ||
"testEnvironment": "node" | ||
"testEnvironment": "node", | ||
"modulePathIgnorePatterns": ["<rootDir>/dist/"] | ||
} |
@@ -6,3 +6,3 @@ { | ||
"homepage": "https://github.com/ovotech/pg-sql-migrate", | ||
"version": "3.3.4", | ||
"version": "4.0.0", | ||
"main": "dist/index.js", | ||
@@ -26,23 +26,20 @@ "types": "dist/index.d.ts", | ||
"@ovotech/config-file": "^1.0.0", | ||
"commander": "^6.2.1", | ||
"pg": "^8.5.0" | ||
"commander": "^9.2.0", | ||
"pg": "^8.7.3" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.19", | ||
"@types/node": "^14.14.14", | ||
"@types/pg": "^7.14.7", | ||
"@typescript-eslint/eslint-plugin": "^4.10.0", | ||
"@typescript-eslint/parser": "^4.10.0", | ||
"eslint": "^7.15.0", | ||
"eslint-config-prettier": "^7.0.0", | ||
"jest": "^26.6.3", | ||
"jest-junit": "^12.0.0", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.4.4", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.3" | ||
}, | ||
"jest": { | ||
"preset": "./jest.config.json" | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^17.0.30", | ||
"@types/pg": "^8.6.5", | ||
"@typescript-eslint/eslint-plugin": "^5.21.0", | ||
"@typescript-eslint/parser": "^5.21.0", | ||
"eslint": "^8.14.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"jest": "^27.5.1", | ||
"jest-junit": "^13.2.0", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^27.1.4", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.4" | ||
} | ||
} |
@@ -80,3 +80,3 @@ import { loadConfigFile } from '@ovotech/config-file'; | ||
} finally { | ||
throw new MigrationError(error.message, migration); | ||
throw new MigrationError(String(error), migration); | ||
} | ||
@@ -83,0 +83,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37441
609
+ Addedcommander@9.5.0(transitive)
- Removedcommander@6.2.1(transitive)
Updatedcommander@^9.2.0
Updatedpg@^8.7.3