migrate icon indicating copy to clipboard operation
migrate copied to clipboard

No proper documentation regarding managing deployments via CICD when using golang-migrate

Open mohanprasathsj opened this issue 2 years ago • 2 comments

In our project we have 3 environments (I believe most dev team will also have such structure), staging, uat and prod. Accordingly our Git CICD pipelines will run all the migration files automatically in all these environments. I am exploring golang-migrate for my team's new project and I am not sure how do we manage the deployments for migrations if I am using go-lang migrate. I have the following questions.

1. How do we handle files once we have migrated all the scripts (files) in all our deployment environments (Whether we will push the files to different folder or will keep the files in the migration folder itself?). * Why I have this question is because, up is working perfectly by just running only the scripts (versions) that has not been executed before. But down is running all the scripts under the folder db\migrations. This is clearing to all the data since the initiation (if I have all the scripts under db\migrations folder). Else, every time I have to know the version to which I have to down (my scripts) to which will be difficult while handling this in CI CD Pipelines.

Can anyone explain what the best practices are on handling the migration in CI/CD.

mohanprasathsj avatar Feb 06 '23 04:02 mohanprasathsj

@mohanprasathsj To run down migrations, you have to run it in up mode with the specified version in the past. It will recognize scripts and apply them.

I think that this is not related to the topic of this repository, but I'll try to share my thoughts.

Probably the best approach will be to write migrations in a backwards-compatible non-breaking way and apply a master everywhere. And only after that deploy the code changes that will cover new functionality added in migrations. If you need to revert the code - it will still work as migrations are backwards-compatible. And after that, revert migrations to the needed version.

obalunenko avatar Jun 29 '23 10:06 obalunenko

I believe most dev team will also have such structure

Don't assume

But down is running all the scripts under the folder db\migrations. This is clearing to all the data since the initiation (if I have all the scripts under db\migrations folder). Else, every time I have to know the version to which I have to down (my scripts) to which will be difficult while handling this in CI CD Pipelines.

That's the expected behavior for down. Are you using a shared DB for CI? Do you have separate pipelines for CI & CD?

dhui avatar Jul 03 '23 05:07 dhui