Squash carbide-api-db migrations#3288
Conversation
This moves to a single snapshotted .sql file of the whole database schema, and archives old migrations to a pre-squash directory. Compatibility with existing deployments is maintained by splitting into three `sqlx::migrate::Migrator` instances: - One for the pre-squash migrations - One for the squashed migration - One for the post-squash migrations Whether we're an existing deployment or not is determined by the presence of the `_sqlx_migrations` table. For existing deployments, they will migrate through the pre-squash migrations first (skipping any we've already migrated), then migrate through the new migrations directory, intentionally skipping the single squash migration via Migrator::skip. For new deployments, the inverse happens: If we don't see a _sqlx_migrations table, we run the squash migration first, then all the other migrations. If other PR's are open at the time this is under review and are merged, it will not cause any issues: We run the squash migration from crates/api-db/migrations first in its own migrator (or skip it if we're an existing deployment running the legacy migrations), *then* we run every other migration in that directory. So if another migration is added, it will still be run at the correct time. The approach generalizes to multiple squashes: We can do all this again in the future and it's just another entry to add to `MIGRATION_LAYOUT`. Also included is a cargo xtask for performing the squashing, using @chet's PR NVIDIA#906 as a base.
|
Important Review skippedToo many files! This PR contains 379 files, which is 79 over the limit of 300. To get a review, narrow the scope: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (379)
You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
🌿 Preview your docs: https://nvidia-preview-pull-request-3288.docs.buildwithfern.com/infra-controller |
🔍 Container Scan Summary
Per-CVE detail lives in the per-service |
|
Transient CICD failure (429 from GH) -- re-running failed jobs. |
This moves to a single snapshotted .sql file of the whole database schema, and archives old migrations to a pre-squash directory.
Compatibility with existing deployments is maintained by splitting into three
sqlx::migrate::Migratorinstances:Whether we're an existing deployment or not is determined by the presence of the
_sqlx_migrationstable.For existing deployments, they will migrate through the pre-squash migrations first (skipping any we've already migrated), then migrate through the new migrations directory, intentionally skipping the single squash migration via Migrator::skip.
For new deployments, the inverse happens: If we don't see a _sqlx_migrations table, we run the squash migration first, then all the other migrations.
If other PR's are open at the time this is under review and are merged, it will not cause any issues: We run the squash migration from crates/api-db/migrations first in its own migrator (or skip it if we're an existing deployment running the legacy migrations), then we run every other migration in that directory. So if another migration is added, it will still be run at the correct time.
The approach generalizes to multiple squashes: We can do all this again in the future and it's just another entry to add to
MIGRATION_LAYOUT.Also included is a cargo xtask for performing the squashing, using @chet's PR #906 as a base.
Related issues
#1077
Type of Change
Breaking Changes
Testing
Additional Notes
Tested locally via devspace, by deploying the main branch via
devspace deploy -n nico-system, then checking out this branch, and doing it again, and ensuring the migration worked and looked as expected. Then did the same after starting the database from scratch and just deploying this branch, verifying the migrations table had a single entry.