Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing default options #601

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions bin/node-pg-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -56,61 +56,64 @@ const { argv } = yargs

.option('m', {
alias: migrationsDirArg,
default: `${process.cwd()}/migrations`,
defaultDescription: 'migrations',
defaultDescription: '"migrations"',
describe: 'The directory containing your migration files',
type: 'string',
})

.option('t', {
alias: migrationsTableArg,
default: 'pgmigrations',
defaultDescription: '"pgmigrations"',
describe: 'The table storing which migrations have been run',
type: 'string',
})

.option('s', {
alias: schemaArg,
default: 'public',
defaultDescription: '"public"',
describe: 'The schema on which migration will be run (defaults to `public`)',
type: 'string',
array: true,
})

.option(createSchemaArg, {
defaultDescription: 'false',
describe: "Creates the configured schema if it doesn't exist",
type: 'boolean',
})

.option(migrationsSchemaArg, {
default: undefined,
defaultDescription: 'Same as "schema"',
describe: 'The schema storing table which migrations have been run',
type: 'string',
})

.option(createMigrationsSchemaArg, {
defaultDescription: 'false',
describe: "Creates the configured migration schema if it doesn't exist",
type: 'boolean',
})

.option(checkOrderArg, {
defaultDescription: 'true',
describe: 'Check order of migrations before running them',
type: 'boolean',
})

.option(verboseArg, {
defaultDescription: 'true',
describe: 'Print debug messages - all DB statements run',
type: 'boolean',
})

.option(ignorePatternArg, {
default: '\\..*',
defaultDescription: '"\\..*"',
describe: 'Regex pattern for file names to ignore',
type: 'string',
})

.option(decamelizeArg, {
defaultDescription: 'false',
describe: 'Runs decamelize on table/columns/etc names',
type: 'boolean',
})
Expand All @@ -123,7 +126,6 @@ const { argv } = yargs

.option('f', {
alias: configFileArg,
default: undefined,
describe: 'Name of config file with db options',
type: 'string',
})
Expand All @@ -137,7 +139,6 @@ const { argv } = yargs
})

.option(tsconfigArg, {
default: undefined,
describe: 'path to tsconfig.json file',
type: 'string',
})
Expand Down Expand Up @@ -168,6 +169,7 @@ const { argv } = yargs
})

.option(rejectUnauthorizedArg, {
defaultDescription: 'false',
describe: 'Sets rejectUnauthorized SSL option',
type: 'boolean',
})
Expand Down Expand Up @@ -296,6 +298,14 @@ if (configFileName) {

const action = argv._.shift()

// defaults
MIGRATIONS_DIR = typeof MIGRATIONS_DIR === 'undefined' ? `${process.cwd()}/migrations` : MIGRATIONS_DIR
MIGRATIONS_TABLE = typeof MIGRATIONS_TABLE === 'undefined' ? 'pgmigrations' : MIGRATIONS_TABLE
SCHEMA = typeof SCHEMA === 'undefined' ? 'public' : SCHEMA
IGNORE_PATTERN = typeof IGNORE_PATTERN === 'undefined' ? '\\..*' : IGNORE_PATTERN
CHECK_ORDER = typeof CHECK_ORDER === 'undefined' ? true : CHECK_ORDER
VERBOSE = typeof VERBOSE === 'undefined' ? true : VERBOSE

if (action === 'create') {
// replaces spaces with dashes - should help fix some errors
let newMigrationName = argv._.length ? argv._.join('-') : ''
Expand Down Expand Up @@ -375,8 +385,8 @@ if (action === 'create') {
count,
timestamp,
file: migrationName,
checkOrder: typeof CHECK_ORDER === 'undefined' ? true : CHECK_ORDER,
verbose: typeof VERBOSE === 'undefined' ? true : VERBOSE,
checkOrder: CHECK_ORDER,
verbose: VERBOSE,
direction,
singleTransaction,
noLock,
Expand Down