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

Atlas hash incorrect order for golang migrate #3017

Open
strowk opened this issue Aug 2, 2024 · 0 comments
Open

Atlas hash incorrect order for golang migrate #3017

strowk opened this issue Aug 2, 2024 · 0 comments

Comments

@strowk
Copy link

strowk commented Aug 2, 2024

Correct order of migrations for golang migrate is not lexicographic, it is supposed to be numeric, with number extracted from file name before underline _.
Unfortunately command atlas migrate hash does not seem to take that into account correctly and starting from migration 10 two things starts to happen:

  • migration 10_whatever.up.sql would appear in the atlas.sum before 1_whatever.up.sql
  • all hashes for files with versions 1-9 would be recalculated again even though files did not change

Then when migration 11 would appear, it would be after 10, but before 1, while still recalculating hashes 1-9, but NOT recalculating hash for 10 (it appears that hash somehow includes all previous versions, with definition of previous being wrong).

Note, I did configure atlas.hcl like so:

  migration {
    dir = "file://./cmd/kodata/migrations"
    format = "golang-migrate"
  }
  format {
    migrate {
      diff = "{{ sql . \"  \" }}"
    }
  }

(as explained in documentation https://atlasgo.io/guides/migration-tools/golang-migrate )

, so altas should be aware of golang-migrate specifics.

I see in that doc that numbers for generated files are timestamps (which is not correct from golang-migrate perspective actually, as they are commonly versions), that would be fine with lexicographic sorting, but I usually rename whatever came out of atlas diff and until version 10 it was not the issue.

I believe that configuring format = "golang-migrate" , should make atlas to start sorting migrations correctly according to what golang migrate says about ordering of migrations.

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

No branches or pull requests

1 participant