Skip to content

test(clickhouse): auto-discover migrations in bundled_migrations() smoke test#249

Merged
eric-tramel merged 1 commit into
mainfrom
claude/objective-borg-82fa56
Apr 19, 2026
Merged

test(clickhouse): auto-discover migrations in bundled_migrations() smoke test#249
eric-tramel merged 1 commit into
mainfrom
claude/objective-borg-82fa56

Conversation

@eric-tramel

Copy link
Copy Markdown
Owner

Summary

  • Replaces the hard-coded assert_eq!(migrations.len(), N) in bundled_migrations_registers_all_sql_files with a directory walk of sql/ that diffs discovered filenames against the names returned by bundled_migrations().
  • Adds two ordering invariants: bundled_migrations() must be sorted ascending by version, and each entry's name must start with its version's numeric prefix.
  • Fixes the silent false-green regression that hit twice — #221 (migration 011) and #230 (migration 012) — where a new sql/NNN_*.sql was added without a matching include_str! entry but the count-based test still passed because N was not bumped.

Closes #233.

How the new check works

  1. std::fs::read_dir($CARGO_MANIFEST_DIR/../../sql) enumerates every file matching ^\d{3}_.+\.sql$.
  2. Result is sorted and compared against bundled_migrations().iter().map(|m| m.name) — assertion failure prints both lists with a diff, so missing/extra entries are immediately visible.
  3. Separate unit test pins the filename matcher's behavior (01_foo.sql, 0001_foo.sql, README.md, etc. are rejected; 001_foo.sql is accepted).

A file registered in bundled_migrations() but missing from disk is already caught at compile time by include_str!, so no runtime check is needed for that direction.

Verification

  • cargo test -p moraine-clickhouse --lib — 12 passed.
  • Manually added a stub sql/099_fake_unregistered.sql and 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

  • New test passes on main as-is.
  • New test fails loudly when a sql/NNN_*.sql is added without a matching bundled_migrations() entry.
  • Filename matcher correctly rejects non-conforming names (covered by dedicated unit test).
  • cargo fmt --all -- --check clean.
  • cargo clippy strict baseline clean.

🤖 Generated with Claude Code

…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
eric-tramel enabled auto-merge (squash) April 19, 2026 04:19
@eric-tramel
eric-tramel merged commit 55d6f51 into main Apr 19, 2026
2 checks passed
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 this pull request may close these issues.

Auto-discover migrations in bundled_migrations() smoke test

1 participant