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

Renaming migrations #1158

Closed
alucryd opened this issue Apr 8, 2021 · 1 comment · Fixed by #1888
Closed

Renaming migrations #1158

alucryd opened this issue Apr 8, 2021 · 1 comment · Fixed by #1888

Comments

@alucryd
Copy link

alucryd commented Apr 8, 2021

Hi there, I was looking for a way to rename a migration (not change its content) or at least force it to reapply (I always try to make them idempotent), but sqlx fails saying its checksum has changed even though it hasn't.

Is that expected, is there a proper way to rename a migration?

@mdtusz
Copy link
Contributor

mdtusz commented Jun 2, 2022

Even without changing the names, I've been running into the issue of sqlx migrate info showing that there's checksum mismatches despite the "old" migrations not being modified at all since they were applied. Even if I nuke my local database and recreate it from scratch, sqlx migrate info will report checksum mismatches 🤔

Rubber-duck edit:

After looking into this a bit, it seems that the checksum reported for the local migration when the check is run is comparing with the foo_migration.down.sql file rather than the foo_migration.up.sql file.

To test this on your own, run sha384sum path/to/your_migration.down.sql and it should match the checksum specified in the sqlx migrate info output. I believe the fix will be to check the migration.type and ignore the checksum mismatch if the migration being iterated through is not a MigrationType::Simple or MigrationType::ReversibleUp.

Relevant code here

I'll make a fix and open a PR to resolve this. It shouldn't require any changes to stored data as it's entirely within the CLI - the checksums stored are correct.

mdtusz added a commit to mdtusz/sqlx that referenced this issue Jun 2, 2022
When running `sqlx migrate info`, the applied migrations checksums are
compared against the checksums of the local migration files. While the
checksums of applied migrations are stored correctly in the database as
sha384sum values, the `migrate info` command was incorrectly comparing
these against the checksums of down-migrations in cases where reversible
migrations are being used (e.g. when migrations end in `.up.sql` and
`.down.sql`).

This fixes the issue by skipping over any migrations with the
`MigrationType::ReversibleDown` type, using the same idiom as is used
when running migrations (with `migrate run`).

Issue introduced in launchbadge#1680
Partially resolves launchbadge#1158
mdtusz added a commit to mdtusz/sqlx that referenced this issue Jun 2, 2022
When running `sqlx migrate info`, the applied migrations checksums are
compared against the checksums of the local migration files. While the
checksums of applied migrations are stored correctly in the database as
sha384sum values, the `migrate info` command was incorrectly comparing
these against the checksums of down-migrations in cases where reversible
migrations are being used (e.g. when migrations end in `.up.sql` and
`.down.sql`).

This fixes the issue by skipping over any migrations with the
`MigrationType::ReversibleDown` type, using the same idiom as is used
when running migrations (with `migrate run`).

Issue introduced in launchbadge#1680
Partially resolves launchbadge#1158
mdtusz added a commit to mdtusz/sqlx that referenced this issue Jun 4, 2022
When running `sqlx migrate info`, the applied migrations checksums are
compared against the checksums of the local migration files. While the
checksums of applied migrations are stored correctly in the database as
sha384sum values, the `migrate info` command was incorrectly comparing
these against the checksums of down-migrations in cases where reversible
migrations are being used (e.g. when migrations end in `.up.sql` and
`.down.sql`).

This fixes the issue by skipping over any migrations with the
`MigrationType::ReversibleDown` type, using the same idiom as is used
when running migrations (with `migrate run`).

Issue introduced in launchbadge#1680
Partially resolves launchbadge#1158
mdtusz added a commit to mdtusz/sqlx that referenced this issue Jun 4, 2022
When running `sqlx migrate info`, the applied migrations checksums are
compared against the checksums of the local migration files. While the
checksums of applied migrations are stored correctly in the database as
sha384sum values, the `migrate info` command was incorrectly comparing
these against the checksums of down-migrations in cases where reversible
migrations are being used (e.g. when migrations end in `.up.sql` and
`.down.sql`).

This fixes the issue by skipping over any migrations with the
`MigrationType::ReversibleDown` type, using the same idiom as is used
when running migrations (with `migrate run`).

Issue introduced in launchbadge#1680
Partially resolves launchbadge#1158
abonander pushed a commit that referenced this issue Jun 10, 2022
When running `sqlx migrate info`, the applied migrations checksums are
compared against the checksums of the local migration files. While the
checksums of applied migrations are stored correctly in the database as
sha384sum values, the `migrate info` command was incorrectly comparing
these against the checksums of down-migrations in cases where reversible
migrations are being used (e.g. when migrations end in `.up.sql` and
`.down.sql`).

This fixes the issue by skipping over any migrations with the
`MigrationType::ReversibleDown` type, using the same idiom as is used
when running migrations (with `migrate run`).

Issue introduced in #1680
Partially resolves #1158
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 a pull request may close this issue.

2 participants