Error on .sql migration files that don't match the expected filename format - #4367
Open
teddytennant wants to merge 1 commit into
Open
Conversation
…PTION>.sql` `resolve_blocking_with_config()` skipped any filename that didn't split into two parts on `_`, so a migration named `schema.sql` (no version prefix) was dropped from the migration set without any diagnostic. `a_schema.sql` already errors on the version parse, so the failure mode depended on whether the file happened to contain an underscore. Return a `ResolveError` naming the file and the expected format when the name ends in `.sql` but doesn't parse. Files that don't end in `.sql` (README, .gitkeep, editor backups) are still ignored silently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4362.
The bug
resolve_blocking_with_config()splits a migration filename on the first_andcontinues if itdoesn't get two parts. A
.sqlfile with no underscore —schema.sql— is therefore dropped fromthe migration set with no error and no warning: the migration runner reports success and the
schema never reaches the database.
The failure mode depends on whether the name happens to contain an underscore.
a_schema.sqlalready hard-errors on the version parse;
schema.sqlis silently ignored. That inconsistency isthe surprising part.
The fix
When a filename fails to parse but ends in
.sql, return aResolveErrornaming the offending fileand the expected
<VERSION>_<DESCRIPTION>.sqlformat. Files that don't end in.sql(README,.gitkeep) are still ignored silently, exactly as before — that behaviour is intentional and ispinned by a second test.
Also updated the
MigrationSourcedoc comment, which claimed "Files that don't match this format aresilently ignored" and is no longer accurate for
.sqlfiles.Verification
Fail-before (test present, source fix reverted):
Pass-after:
Baseline before any edit was 4 passed / 0 failed — no pre-existing failures.
cargo test --test migrate-macro --no-default-features --features runtime-tokio,tls-none,macros,migrate,sqlitepasses, exercising both the
migrate!compile-time path and the runtime path over the repo's threefixture migration directories.
cargo fmt --all -- --checkclean.cargo clippy -p sqlx-core --all-targets -- -D warningsclean.I also swept every
migrations*/directory in the repo, including examples and sqlx-cli fixtures:zero files that the new error would reject.
Is this a breaking change?
Behaviourally, yes — a
.sqlfile that previously resolved to nothing now errors. The issue asks for"an error (or warning)", and the consistency argument is strong since
a_schema.sqlalready errors.If you'd rather this were a
tracing::warn!for a 0.9.x patch release, say the word and I'll switchit.
Deliberately not done
The other option in the issue — actually supporting version-less migrations — is a feature decision
with ordering and checksum implications, not a bug fix, so I left it alone.