Skip to content

fix(migrations): case-sensitive migration rollback detection #3919

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

Conversation

0xSherlokMo
Copy link
Contributor

@0xSherlokMo 0xSherlokMo commented Apr 3, 2025

This PR fixes an issue where SQLC was failing to properly detect and remove rollback statements in migration files due to case sensitivity. Previously, SQLC only recognized uppercase Down in rollback statements (e.g., -- +goose Down), but migration tools like Goose have updated their documentation to use lowercase down (e.g., -- +goose down).

The change makes the rollback statement detection case-insensitive by converting the statement to lowercase before checking, ensuring compatibility with:

  • Both -- +goose Down and -- +goose down (Goose migrations)
  • Both -- +migrate Down and -- +migrate down (sql-migrate)
  • Case variations in other migration tool formats

This maintains backward compatibility with existing migrations while supporting the current documentation standards of migration tools.

Fixes issue #3444

Changes

  • Modified RemoveRollbackStatements to perform case-insensitive comparison by converting statements to lowercase before checking
  • Maintains support for all existing migration tool formats:
    • Goose
    • sql-migrate
    • tern
    • dbmate

Testing

  • Verified that both uppercase and lowercase rollback statements are properly detected and removed
  • Ensures no breaking changes for existing migration files

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 3, 2025
@kyleconroy kyleconroy merged commit 94c0170 into sqlc-dev:main Apr 11, 2025
8 checks passed
@kyleconroy
Copy link
Collaborator

@0xSherlokMo appreciate the simple change and the excellent explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants