From ad784eb5a536d3c3ad92cd2987c783beb6d5be44 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Tue, 20 Jun 2017 00:44:43 +0300 Subject: [PATCH] add support for running all migration files regardless of timestamp --- bin/rethinkdb-migrate | 5 ++++- lib/migrate.js | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/rethinkdb-migrate b/bin/rethinkdb-migrate index 5695093..25bc4ca 100755 --- a/bin/rethinkdb-migrate +++ b/bin/rethinkdb-migrate @@ -73,6 +73,9 @@ require('yargs') .alias('f', 'file') .nargs('f', 1) .describe('f', 'Uses the provided file as the options to be used when migration is run') + .alias('i', 'ignore-timestamp') + .nargs('i', 0) + .describe('i', 'Ignore timestamp when applying migrations') .help('h') .alias('h', 'help') .demandCommand(1) @@ -111,7 +114,7 @@ function logger (emitter) { * an option present in the config file and also a environment variable, and so on */ function buildOptions (argv) { - const optionsMask = 'name,migrationsDirectory,relativeTo,migrationsTable,host,port,db,user,username,password,authKey,driver,discovery,pool,cursor,servers,ssl' + const optionsMask = 'name,migrationsDirectory,relativeTo,migrationsTable,host,port,db,user,username,password,authKey,driver,discovery,pool,cursor,servers,ssl,i' const envVars = Mask(process.env, optionsMask) const file = Mask(readOptionsFile(argv), optionsMask) const args = Mask(argv, optionsMask) diff --git a/lib/migrate.js b/lib/migrate.js index 3610eab..0d89573 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -35,6 +35,8 @@ function validateOptions (options) { .description('Rethinkdb javascript driver'), migrationsTable: Joi.string().default('_migrations') .description('Table where meta information about migrations will be saved'), + i: Joi.boolean().default(0) + .description('Ignore timestamp when applying migrations'), migrationsDirectory: Joi.string().default('migrations') .description('Directory where migration files will be saved'), relativeTo: Joi.string().default(process.cwd()) @@ -233,7 +235,7 @@ function getUnExecutedMigrations (latestExecutedMigration, options) { filename } })) - .then(migrations => filterMigrationsOlderThan(migrations, latestExecutedMigration.timestamp)) + .then(migrations => filterMigrationsOlderThan(migrations, latestExecutedMigration.timestamp, options)) .then(sortMigrations) .then(migrations => loadMigrationsCode(migrations, options)) } @@ -249,8 +251,11 @@ function readMigrationFilenamesFromPath (path) { }) } -function filterMigrationsOlderThan (migrations, reference) { - return migrations.filter(migration => migration.timestamp.isAfter(Moment(reference))) +function filterMigrationsOlderThan (migrations, reference, options) { + if (!options.i) { + return migrations.filter(migration => migration.timestamp.isAfter(Moment(reference))) + } + return migrations } function loadMigrationsCode (migrations, options) {