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

add support for running all migration files regardless of timestamp #21

Merged
merged 1 commit into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion bin/rethinkdb-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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))
}
Expand All @@ -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) {
Expand Down