pg-flyway
Version:
Migration tool for PostgreSQL database, NodeJS version of Java migration tool - flyway (not wrapper for https://flywaydb.org/documentation/commandline)
37 lines (36 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createEmptyMigrationHandlerOptions = createEmptyMigrationHandlerOptions;
exports.createEmptyMigration = createEmptyMigration;
const commander_1 = require("commander");
const default_1 = require("../constants/default");
const env_keys_1 = require("../constants/env-keys");
const create_empty_migration_service_1 = require("../services/create-empty-migration.service");
async function createEmptyMigrationHandlerOptions(options) {
const createEmptyMigrationService = new create_empty_migration_service_1.CreateEmptyMigrationService({
locations: options.locations.split(',').map((s) => s.trim()),
sqlMigrationSuffixes: options.sqlMigrationSuffixes.split(',').map((s) => s.trim()),
sqlMigrationSeparator: options.sqlMigrationSeparator,
});
await createEmptyMigrationService.createEmptyMigration({
name: options.name,
version: options.version,
});
}
function createEmptyMigration(program) {
program
.command('create')
.description('Create empty migration named by mask "VyyyyMMddkkmm__Name.sql" (example: V202501151755__Init.sql, Date field symbol table: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)')
.addOption(new commander_1.Option('-n,--name <strings>', 'Name the migration').makeOptionMandatory())
.addOption(new commander_1.Option('-v,--version <strings>', 'Static version, if the value is not passed, then use the current date and time in the format "yyyyMMddkkmm"'))
.addOption(new commander_1.Option('-l,--locations <strings>', 'Locations with migration files')
.default(default_1.PG_FLYWAY_DEFAULT_CREATE_EMPTY_MIGRATION_CONFIG.locations)
.env(env_keys_1.PG_FLYWAY_LOCATIONS))
.addOption(new commander_1.Option('-s,--sql-migration-suffixes <strings>', 'Extension of migration files')
.default(default_1.PG_FLYWAY_DEFAULT_CREATE_EMPTY_MIGRATION_CONFIG.sqlMigrationSuffixes)
.env(env_keys_1.PG_FLYWAY_SQL_MIGRATION_SUFFIXES))
.addOption(new commander_1.Option('--sql-migration-separator <strings>', 'Version separator (example: V1__Name.sql, sqlMigrationSeparator= "__")')
.default(default_1.PG_FLYWAY_DEFAULT_CREATE_EMPTY_MIGRATION_CONFIG.sqlMigrationSeparator)
.env(env_keys_1.PG_FLYWAY_SQL_MIGRATION_SEPARATOR))
.action((options) => createEmptyMigrationHandlerOptions(options));
}