Migrations can be created and are ran during upgrade #1938
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Migrations
Migration files are simple they export a down and an up function. Up should make the changes you want and return the callback. Down should revert changes made by up if possible, this allows easier testing and downgrading of a release if needed.
The migration library works by looking in a folder for migration files and comparing the files there to a DB table where it stores the ran state. Any migrations that have not been run will have a state of down and it will run them.
The migration lib needs a DB connection string because every install can be different its easiest to generate this into a config file for it. I've done this on grunt build that way if someone updates the DB details they just need to run grunt build.
Migrations are not run on install but any new ones will run on upgrade. On install, we need to add any existing ones and mark them as done.
Unfortunately, the release where we add this we cant run migrations because each release uses the last release's upgrade file so it would be good to get this in asap.
To create a migration
To create a migration you can run
npm run migrate create <name>
. This will create a new file from the template inmigrations/libs
.To run a migration from the command line (to test)
To create a migration you can run
npm run migrate up <name>
,npm run migrate down <name>
will revert it.Fixes #1937