Skip to content

feat(ci): add migration-police for migration filenames - #4433

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-4431
Jul 31, 2026
Merged

feat(ci): add migration-police for migration filenames#4433
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-4431

Conversation

@chet

@chet chet commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What happened

The failures on #4422 and #4424 looked flaky because they surfaced as a very large test cascade, but the underlying failure was deterministic: SQLx migration versions are keyed by the numeric timestamp prefix, and two different migration files had the same version.

On #4422, these files both used 20260722120000:

  • 20260722120000_bmc_suppressions.sql
  • 20260722120000_preserve_machine_ipv6_loopback.sql

That made template-database migration fail on the _sqlx_migrations_pkey constraint. Every database-backed test that tried to create a template then failed from the same setup error, producing 1,114 failures rather than 1,114 independent test bugs.

Two stale fixes later composed on #4424 and moved both files to 20260722120001, recreating the same collision under a different version. #4432 repaired main by restoring the already-published loopback migration to 20260722120000 and leaving the newer BMC migration at 20260722120001; the SQL contents themselves did not change.

What this changes

This adds a separate migration-police job that looks only at migration files newly added by a pull request and rejects timestamp prefixes whose minute and second fields are both 00. New Core migrations must use a fully populated YYYYMMDDhhmmss_description.sql timestamp.

The existing duplicate-version test remains the definitive backstop once migrations are in the same tree. This earlier CI rule reduces the chance that independent branches choose the same convenient ...0000 placeholder before they can be compared together. Existing migrations remain accepted.

The checker compares the PR head with the merge base (base...HEAD), so a stale PR does not incorrectly claim that a migration renamed only on main was added by the PR. STYLE_GUIDE.md and AGENTS.md document the same naming rule.

Related issues

Fixes #4431

Related failure investigations: #4422, #4424

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Focused checks covered:

  • accepting a valid fully populated timestamp
  • rejecting a 0000 minute/second placeholder
  • accepting zero seconds when the minute is populated
  • rejecting malformed migration basenames
  • a stale PR whose migration was renamed only on main
  • invalid base-revision handling
  • shell syntax, workflow YAML parsing, and git diff --check
  • cargo test -p carbide-api-db migration_versions_are_unique --lib

The required local gates passed:

  • cargo make format-nightly
  • cargo make clippy
  • cargo make carbide-lints

Local CodeRabbit produced no findings. Claude review identified the stale-PR two-dot diff problem; the checker was changed to merge-base diff semantics and the stale #4422 branch was used as a focused regression case. Cloud CodeRabbit subsequently completed a full review of the amended commit with no actionable findings.

Additional Notes

The immediate migration collision is already repaired on current main by #4432. This PR prevents the naming pattern that allowed two independent branches to select the same placeholder timestamp; it does not rename published migrations.

Closes #4431

@chet
chet requested review from a team as code owners July 31, 2026 04:49
@chet

chet commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@chet: I will perform a complete review of pull request #4433.

🐇✅

✅ Action performed

Full review finished.

@chet chet changed the title feat(ci): add migration-police for placeholder timestamps feat(ci): add migration-police for migration file/placeholder timestamps Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added automated validation to ensure new database migration filenames follow the required 14-digit timestamped format.
    • Pull requests now report invalid migration filenames and block the core CI check when issues are found.
    • Validation supports checking selected migration files or comparing changes against a specified base revision.
  • Documentation

    • Documented database migration naming requirements and clarified that existing migrations remain unchanged.

Walkthrough

The change defines a timestamped naming format for new Core database migrations. A Bash checker validates newly added migration filenames. Pull-request CI runs the checker and requires its result in core-ci-pass.

Changes

Migration filename validation

Layer / File(s) Summary
Migration naming contract
AGENTS.md, STYLE_GUIDE.md
The documentation requires YYYYMMDDhhmmss_description.sql for new migrations and preserves existing filenames.
Validation script and CI integration
scripts/check-migration-filenames.sh, .github/workflows/ci.yaml
The script supports explicit files and --base REVISION, validates migration timestamps, reports GitHub Actions errors, and returns failure for invalid files. Pull-request CI runs migration-police and adds it to core-ci-pass.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PullRequest
  participant GitHubActions
  participant MigrationChecker
  participant CoreCIPass
  PullRequest->>GitHubActions: Open or update pull request
  GitHubActions->>MigrationChecker: Run with origin/main as base
  MigrationChecker->>MigrationChecker: Validate newly added migration filenames
  MigrationChecker-->>GitHubActions: Return validation status
  GitHubActions->>CoreCIPass: Report migration-police status
Loading

Possibly related issues

  • NVIDIA/infra-controller/4431: The pull request implements the issue’s migration timestamp validation, CI job, documentation, and required CI aggregation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the new migration-policing CI job and its filename validation purpose.
Description check ✅ Passed The description explains the migration collision issue, the new CI validation, documentation updates, testing, and intended behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@chet chet changed the title feat(ci): add migration-police for migration file/placeholder timestamps feat(ci): add migration-police for migration filenames Jul 31, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/check-migration-filenames.sh`:
- Around line 53-61: Update the migration filename validation in
check-migration-filenames.sh to validate the complete basename against the
required YYYYMMDDhhmmss_description.sql format before checking for the trailing
0000 placeholder. Preserve the existing placeholder error behavior for otherwise
valid filenames, and reject malformed new migration filenames under the
documented contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9a98aff7-dc45-4e7b-b44b-b1002261d87f

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7e5d0 and ef337a3.

📒 Files selected for processing (4)
  • .github/workflows/ci.yaml
  • AGENTS.md
  • STYLE_GUIDE.md
  • scripts/check-migration-filenames.sh

Comment thread scripts/check-migration-filenames.sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yaml:
- Line 1370: Update the workflow’s push branch pattern to match pull-request
branches under pull-request/ using GitHub Actions glob syntax, such as
pull-request/**, while preserving the existing github.ref condition for the
push-based flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: aab48b08-8832-46b3-83c7-67893426a848

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7e5d0 and ef337a3.

📒 Files selected for processing (4)
  • .github/workflows/ci.yaml
  • AGENTS.md
  • STYLE_GUIDE.md
  • scripts/check-migration-filenames.sh

Comment thread .github/workflows/ci.yaml
@chet

chet commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@chet: I will perform a complete review of pull request #4433.

🐇✅

✅ Action performed

Full review finished.

@chet
chet enabled auto-merge (squash) July 31, 2026 06:08
Core migrations have historically used `...120000` placeholder timestamps, which means two independently authored PRs can both look fine until their versions collide on `main` -- exactly what NVIDIA#4432 is repairing now. The duplicate-version test can tell us once both migrations are together, but it cannot prevent that collision while the PRs are still independent.

So, this adds a separate `migration-police` job that looks only at new files under `crates/api-db/migrations/` and rejects timestamps whose minute and second fields are both `00`. Existing migrations stay accepted, and failures name the migration plus the required `YYYYMMDDhhmmss_description.sql` format in the job log.

`STYLE_GUIDE.md` and `AGENTS.md` now point contributors at the same fully populated timestamp rule.

This supports NVIDIA#4431

Signed-off-by: Chet Nichols III <chetn@nvidia.com>

chet commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@chet: I will perform a complete review of pull request #4433.

🐇✅

✅ Action performed

Full review finished.

@chet
chet requested review from lachen-nv, nick-vetro and poroh July 31, 2026 08:45
@chet
chet merged commit 45ea84d into NVIDIA:main Jul 31, 2026
114 of 116 checks passed
@chet
chet deleted the gh-issue-4431 branch July 31, 2026 15:11
polarweasel pushed a commit to polarweasel/infra-controller that referenced this pull request Jul 31, 2026
This enforces that migration files have their timestamp fully populated,
and not end in `0000`.

Core migrations have more recently been using `...120000` placeholder
timestamps, which means two independently authored PRs can both look
fine until their versions collide on `main` -- exactly what NVIDIA#4432 is
repairing now. The duplicate-version test can tell us once both
migrations are together, but it cannot prevent that collision while the
PRs are still independent.

So, this adds a separate `migration-police` job that looks only at new
files under `crates/api-db/migrations/` and rejects timestamps whose
minute and second fields are both `00`. Existing migrations stay
accepted, and failures name the migration plus the required
`YYYYMMDDhhmmss_description.sql` format in the job log.

`STYLE_GUIDE.md` and `AGENTS.md` now point contributors at the same
fully populated timestamp rule.

## Related issues

This supports NVIDIA#4431

## Type of Change

- [x] **Add** - New feature or capability
- [ ] **Change** - Changes in existing functionality
- [ ] **Fix** - Bug fixes
- [ ] **Remove** - Removed features or deprecated functionality
- [ ] **Internal** - Internal changes (refactoring, tests, docs, etc.)

## Breaking Changes

- [ ] **This PR contains breaking changes**

## Testing

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [x] Manual testing performed
- [ ] No testing required (docs, internal refactor, etc.)

Focused checks covered a valid full timestamp, a rejected `0000`
placeholder, an accepted zero-seconds timestamp with a populated minute,
historical migrations against `origin/main`, an invalid base revision,
shell syntax, workflow YAML parsing, and `git diff --check`.

The required local gates also passed:

- `cargo make format-nightly`
- `cargo make clippy`
- `cargo make carbide-lints`

## Additional Notes

`cargo test -p carbide-api-db migration_versions_are_unique --lib`
currently fails on the pre-existing duplicate `20260722120001` migration
version. NVIDIA#4432 repairs that collision and reports the migration test
passing.

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
Signed-off-by: Alex Ball <aball@nvidia.com>
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.

Reject Placeholder Database Migration Timestamps

4 participants