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

Migrations can be created and are ran during upgrade #1938

Merged
merged 4 commits into from
May 14, 2018

Conversation

canstudios-louisem
Copy link
Contributor

@canstudios-louisem canstudios-louisem commented Apr 6, 2018

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 in migrations/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

@canstudios-louisem
Copy link
Contributor Author

Looks like migrate-mongoose is not compatable with node 4 hence th failing tests are we happy to stop testing that now? We havent supported it for a while.

@taylortom
Copy link
Member

Yeah I'm happy for us to drop v4 in v0.6

@dancgray
Copy link
Member

Seems to work pretty well with the commands to create a template: npm run migrate create <name>, and to run a migration: npm run migrate up <name>.

@taylortom
Copy link
Member

Works well for me. Can we add an fs.ensureDir to make sure there's a lib folder in migrations? This threw an error for me.

Also a side-note for others testing: you may need to run grunt migration-conf if you're just checking out the branch in a current install.

@taylortom
Copy link
Member

Note: I remove Node 4 and 5 in #1766, so the broken test shouldn't stop us merging.

@taylortom taylortom merged commit f68fa3e into adaptlearning:develop May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants