test(clickhouse): auto-discover migrations in bundled_migrations() smoke test#249
Merged
Conversation
…oke test Replaces the length-based assertion in bundled_migrations_registers_all_sql_files with a directory walk of sql/ that diffs discovered filenames against the names returned by bundled_migrations(). Catches the regression where a new sql/NNN_*.sql file is added without a matching include_str! entry — previously the test silently passed because the hard-coded count was not bumped (hit twice: #221, #230). Also asserts versions are ordered ascending and that each entry's name starts with its version's numeric prefix. Fixes #233 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
eric-tramel
enabled auto-merge (squash)
April 19, 2026 04:19
4 tasks
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.
Summary
assert_eq!(migrations.len(), N)inbundled_migrations_registers_all_sql_fileswith a directory walk ofsql/that diffs discovered filenames against the names returned bybundled_migrations().bundled_migrations()must be sorted ascending byversion, and each entry'snamemust start with its version's numeric prefix.sql/NNN_*.sqlwas added without a matchinginclude_str!entry but the count-based test still passed becauseNwas not bumped.Closes #233.
How the new check works
std::fs::read_dir($CARGO_MANIFEST_DIR/../../sql)enumerates every file matching^\d{3}_.+\.sql$.bundled_migrations().iter().map(|m| m.name)— assertion failure prints both lists with a diff, so missing/extra entries are immediately visible.01_foo.sql,0001_foo.sql,README.md, etc. are rejected;001_foo.sqlis accepted).A file registered in
bundled_migrations()but missing from disk is already caught at compile time byinclude_str!, so no runtime check is needed for that direction.Verification
cargo test -p moraine-clickhouse --lib— 12 passed.sql/099_fake_unregistered.sqland reran the test: it now fails with the full filename diff pointing at the unregistered file, then cleaned up.cargo clippy --workspace --all-targets --locked -- -Dwarnings(strict baseline) — clean.Test plan
mainas-is.sql/NNN_*.sqlis added without a matchingbundled_migrations()entry.cargo fmt --all -- --checkclean.cargo clippystrict baseline clean.🤖 Generated with Claude Code