./node_modules/db-migrate/bin/db-migrate create myMigrationName
This will create a date stamped *boilerplate migration file for you in the ./migrations
directory, such as 20190625114200-myMigrationName.js .
Modify this file to implement your migration.
./node_modules/db-migrate/bin/db-migrate up
-
Move your newly generated migration file out of the migrations folder(ie. 20190625114200-myMigrationName.js). This is to ensure a clean state to test your new migration against.
-
Run the following command to load a dump file and apply all existing migrations:
cd dumps_folder && mongorestore -d epic some_unzipped_dump/
cd eagle_api_root/ && ./node_modules/db-migrate/bin/db-migrate up
node migrateDocuments.js
-
Put your new migration file back into the /migrations folder and run:
./node_modules/db-migrate/bin/db-migrate up
** This won't unclobber data, just allow a rerun of a migration. You may need to dump and restore if the last migration attempt mangled data. **
-
View all migrations applied, in mongo shell
db.migrations.find()
-
The most recent migration will be at the bottom of the list
db.migrations.deleteOne({ _id: ObjectId(my_most_recent_migrationd_id)})