fix(sqlite): preserve channel references during migration - #4
Conversation
SQLite executes ON DELETE actions when the migration drops the channel table with foreign keys enabled. Pause enforcement around an explicit transactional rebuild, preserve channel rows on rollback, and cover both directions with the real embedded migration.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe SQLite channel migration now rebuilds the table without discarding rows, preserves referencing video rows, manages foreign-key enforcement and transactions, and validates forward and reverse migrations with an in-memory SQLite test. ChangesSQLite channel migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The migration now preserves channel references during SQLite table replacement and restores foreign-key enforcement, with regression and data-integrity checks covering the change. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Would Approve Macroscope's review found this PR approvable — This is a narrowly scoped SQLite migration correction that preserves channel-dependent rows during the table rebuild and restores foreign-key enforcement afterward. The accompanying regression test covers both referenced data retention and migration cleanup without changing application APIs or introducing new production components. Not approved because:
Review your spending limits in Billing settings. You can add or adjust custom eligibility rules. Learn more. |
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issues identified. The migration preserves the existing channel schema apart from the intended avatar nullability change, protects dependent rows during both migration directions, and tests the embedded migration’s apply and revert paths with foreign-key enforcement and integrity checks.
|
| Filename | Overview |
|---|---|
| migrations/sqlite/2026-08-18-132346-0000_channel/up.sql | Rebuilds the channel table with foreign keys paused and an explicit transaction, preserving dependent rows while making avatar nullable. |
| migrations/sqlite/2026-08-18-132346-0000_channel/down.sql | Restores the non-null avatar schema while copying existing channels and safely coercing null avatars. |
| migrations/sqlite/2026-08-18-132346-0000_channel/metadata.toml | Disables Diesel's outer transaction so the migration can change SQLite foreign-key enforcement before beginning its own transaction. |
| src/main.rs | Adds a regression test that applies and reverts the real embedded migration while checking row preservation and foreign-key integrity. |
Reviews (1): Last reviewed commit: "fix(sqlite): preserve channel references..." | Re-trigger Greptile
The upstream channel-avatar migration rebuilds SQLite's
channeltable while foreign keys are enabled. Dropping that parent table executesON DELETEactions; a replay against the production backup deleted all 42,923 video rows.Run the rebuild outside Diesel's transaction so foreign-key enforcement can be paused, then perform the table replacement inside an explicit transaction and re-enable enforcement afterward. The rollback now copies channel rows instead of dropping them, using an empty avatar when reverting a nullable value.
A regression test applies and reverts the real embedded migration with a video referencing its channel. It checks that both rows survive, foreign keys are re-enabled, and no violations remain.
Verification:
cargo test --all-targets: 38 passedcargo clippy --all-targets -- -D warnings: cleanforeign_key_checkreturned zero violations andintegrity_checkreturnedok