I am working on a Rails API, with 2 branches corresponding to my development and production environments.
I have a number of migrations ahead in my development branch, but we recently discover a bug on production that requires to add a migration on the database. However, I need to deploy this fix before merging the current state of develop, as we need extensive testing before shooting to production.
How can I handle this case ? My concern is that if I push the fix on production, the migrations on develop won’t be taken in consideration after, as they are prior to the fix one.
>Solution :
-
You can branch out of your current production state, fix, test then merge,
-
At this point, you can also merge the current state of the development branch into the production branch, which will include all the migrations that were created in development.
-
If the migration timestamp of the fix is larger than the development migrations, this could cause issues in the database if the development migrations are depending on the changes introduced by the fix migration.
-
To avoid such issues, you can consider changing the timestamp of the fix migration to be smaller than the timestamp of the latest migration in the development branch. This way, the fix migration will be applied before the migrations in the development branch, and any dependencies will be resolved correctly.
-
You have to adjust the timestamps before running the migration