Skip to content

Commit

Permalink
Merge 066fd82 into 5dab3a5
Browse files Browse the repository at this point in the history
  • Loading branch information
zbmott committed May 21, 2019
2 parents 5dab3a5 + 066fd82 commit 930cab2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions bin/cli.js
Expand Up @@ -123,6 +123,10 @@ function invoke(env) {
'--migrations-directory [path]',
'Set migrations directory without a knexfile.'
)
.option(
'--migrations-table-name [path]',
'Set migrations table name without a knexfile.'
)
.option(
'--env [name]',
'environment, default: process.env.NODE_ENV || development'
Expand Down
3 changes: 2 additions & 1 deletion bin/utils/cli-config-utils.js
@@ -1,4 +1,4 @@
const { DEFAULT_EXT } = require('./constants');
const { DEFAULT_EXT, DEFAULT_TABLE_NAME } = require('./constants');
const { resolveClientNameWithAliases } = require('../../lib/helpers');
const fs = require('fs');

Expand All @@ -21,6 +21,7 @@ function mkConfigObj(opts) {
connection: opts.connection,
migrations: {
directory: opts.migrationsDirectory,
tableName: opts.migrationsTableName || DEFAULT_TABLE_NAME,
},
},
};
Expand Down
2 changes: 2 additions & 0 deletions bin/utils/constants.js
@@ -1,5 +1,7 @@
const DEFAULT_EXT = 'js';
const DEFAULT_TABLE_NAME = 'knex_migrations';

module.exports = {
DEFAULT_EXT,
DEFAULT_TABLE_NAME,
};
25 changes: 22 additions & 3 deletions test/jake/jakelib/migrate-test.js
Expand Up @@ -94,9 +94,9 @@ test('Run migrations', (temp) =>
)
.then(() =>
assertExec(`${KNEX} migrate:latest \
--client=sqlite3 --connection=${temp}/db \
--migrations-directory=${temp}/migrations \
create_rule_table`)
--client=sqlite3 --connection=${temp}/db \
--migrations-directory=${temp}/migrations \
create_rule_table`)
)
.then(() => assertExec(`ls ${temp}/db`, 'Find the database file'))
.then(() => new sqlite3.Database(temp + '/db'))
Expand All @@ -110,6 +110,25 @@ test('Run migrations', (temp) =>
)
.then((row) => assert.equal(row.name, '000_create_rule_table.js')));

test('run migrations without knexfile and with --migrations-table-name', (temp) =>
assertExec(`${KNEX} migrate:latest \
--client=sqlite3 --connection=${temp}/db \
--migrations-directory=test/jake-util/knexfile_migrations \
--migrations-table-name=custom_migrations_table`)
.then(() => new sqlite3.Database(temp + '/db'))
.then(
(db) =>
new Promise((resolve, reject) =>
db.get(
"SELECT name FROM sqlite_master where type='table' AND name='custom_migrations_table'",
function(err, row) {
err ? reject(err) : resolve(row);
}
)
)
)
.then((row) => assert.equal(row.name, 'custom_migrations_table')));

test('migrate:latest prints non verbose logs', (temp) => {
const db = knexfile.connection.filename;
if (fs.existsSync(db)) {
Expand Down

0 comments on commit 930cab2

Please sign in to comment.