seppevs / migrate-mongo

A database migration tool for MongoDB in Node
MIT License
931 stars 166 forks source link

Add -md command line param to set migrationsDir property #449

Open haxwell opened 3 months ago

haxwell commented 3 months ago

Adds a command line parameter to set the migrationsDir property.

Imagine a program which generates two types of migration scripts, 1) for schemas, and also 2) to insert test data. Initially, I was putting the two types in a single directory, but I ran into a problem in that the schema scripts need to be applied before the insert-test-datas, otherwise you may lose test data. My solution was to enforce the logic of "schemas-before-test-data" in the program, by creating a directory for each type of migration, and then calling the schemas to be migrate-mongo up'd first, and then the test-datas.

However, the directory which migration scripts are read from/written to is determined by the migrationDirs property in the migrate-mongo-config.js file. So to output to/read from the individual type directories, I would need to edit this file to refer to one or the other before calling migrate-mongo.

It was easier modify migrate-mongo to accept a command line parameter, than to deal with programatically editing via awk/sed, the config file.

Checklist