I am working on a new project and wanted to start with a relational DB and I was wondering where in the pipeline should I run the migrations.
Would they be part of the deployment process or during app startup after deployment? Or maybe somewhere else?
Liquibase - after you've deployed the new application, run the liquibase script which will migrate your DB and then immediately switch to the new version. If you need to rollback, rollback the app as well as the DB.
See: liquibase.org
Most people find migration tricky. Some frameworks like Django and Rails generate migration scripts from the object definitions, and you are expected to run the scripts as part of the deployment process, but I never found them complete or as optimized as doing it yourself, especially if the migration is complex like when the data model has undergone significant change.
In the past, I have constructed the migration scripts by hand (since I did not use an ORM like Django). The deployments had 3 flavors:
I found the following issues in that method:
If I had to design this all over again, I think I'd do the following:
Liquibase does seem promising, but I am not sure it can handle complex update queries that not only changes the schema, but also migrates data to adhere to data model changes.