fix: migration fix for drop columns for calendar aligned - #3614
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe migration migrationDropLegacyCalendarAlignedColumns now issues raw ChangesLegacy Column Migration Update
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
Confidence Score: 3/5The migration prevents the boot crash it targets, but the raw SQL introduced will silently fail to drop the columns on SQLite in all environments — not just those with FK violations — because the On SQLite, framework/configstore/migrations.go — specifically the two raw SQL strings at lines 7700 and 7703 Important Files Changed
Reviews (2): Last reviewed commit: "fix: migration test fix" | Re-trigger Greptile |
The merge-base changed after approval.
701538d to
d9ddcf8
Compare
d9ddcf8 to
8016d05
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
framework/configstore/migrations.go (1)
7696-7705: ⚡ Quick winAvoid unconditional drop attempts to keep warning logs actionable.
This currently logs warnings for both real failures and expected “column already absent” cases. Since
hasColumnalready exists, pre-check before issuingDROP COLUMNso warnings represent actual failures.♻️ Proposed change
Migrate: func(tx *gorm.DB) error { tx = tx.WithContext(ctx) // Use raw `ALTER TABLE ... DROP COLUMN IF EXISTS` instead of GORM's Migrator.DropColumn, // which on SQLite does a full table rebuild that aborts on pre-existing FK violations; // since these unconstrained boolean columns are safe to leave behind, we log a warning // rather than fail boot. - if err := tx.Exec("ALTER TABLE governance_budgets DROP COLUMN calendar_aligned").Error; err != nil { - log.Printf("[Migration] warning: could not drop legacy calendar_aligned column from governance_budgets: %v", err) + if has, err := hasColumn(tx, "governance_budgets", "calendar_aligned"); err != nil { + log.Printf("[Migration] warning: could not introspect governance_budgets.calendar_aligned: %v", err) + } else if has { + if err := tx.Exec("ALTER TABLE governance_budgets DROP COLUMN calendar_aligned").Error; err != nil { + log.Printf("[Migration] warning: could not drop legacy calendar_aligned column from governance_budgets: %v", err) + } } - if err := tx.Exec("ALTER TABLE governance_rate_limits DROP COLUMN calendar_aligned").Error; err != nil { - log.Printf("[Migration] warning: could not drop legacy calendar_aligned column from governance_rate_limits: %v", err) + if has, err := hasColumn(tx, "governance_rate_limits", "calendar_aligned"); err != nil { + log.Printf("[Migration] warning: could not introspect governance_rate_limits.calendar_aligned: %v", err) + } else if has { + if err := tx.Exec("ALTER TABLE governance_rate_limits DROP COLUMN calendar_aligned").Error; err != nil { + log.Printf("[Migration] warning: could not drop legacy calendar_aligned column from governance_rate_limits: %v", err) + } } return nil },🤖 Prompt for 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. In `@framework/configstore/migrations.go` around lines 7696 - 7705, The migration currently unconditionally runs tx.Exec("ALTER TABLE ... DROP COLUMN calendar_aligned") and logs warnings even when the column is simply absent; change it to first call hasColumn(tx, "governance_budgets", "calendar_aligned") and only run the ALTER TABLE when hasColumn returns true, then log an error only if the Exec fails; do the same for "governance_rate_limits" using hasColumn(tx, "governance_rate_limits", "calendar_aligned") so warnings represent real failures and not the expected missing-column case.
🤖 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.
Nitpick comments:
In `@framework/configstore/migrations.go`:
- Around line 7696-7705: The migration currently unconditionally runs
tx.Exec("ALTER TABLE ... DROP COLUMN calendar_aligned") and logs warnings even
when the column is simply absent; change it to first call hasColumn(tx,
"governance_budgets", "calendar_aligned") and only run the ALTER TABLE when
hasColumn returns true, then log an error only if the Exec fails; do the same
for "governance_rate_limits" using hasColumn(tx, "governance_rate_limits",
"calendar_aligned") so warnings represent real failures and not the expected
missing-column case.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1bbbc576-6644-4bdb-b363-bb9f40dfd549
📒 Files selected for processing (1)
framework/configstore/migrations.go
Merge activity
|
## Summary Fixes a boot failure caused by GORM's `Migrator.DropColumn` performing a full SQLite table rebuild, which aborts when pre-existing foreign key violations are present. The migration that drops the legacy `calendar_aligned` columns from `governance_budgets` and `governance_rate_limits` is updated to use raw SQL instead, avoiding the rebuild entirely. ## Changes - Replaced `gorm.Migrator.HasColumn` / `DropColumn` calls in `migrationDropLegacyCalendarAlignedColumns` with raw `ALTER TABLE ... DROP COLUMN IF EXISTS` statements. - Since these are unconstrained boolean columns with no data integrity implications, failures are now logged as warnings rather than returned as errors, preventing a hard boot failure in environments with FK violations. ## Type of change - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test Run the migration against a SQLite database that has pre-existing foreign key violations and confirm the application boots successfully without erroring on the `drop_legacy_calendar_aligned_columns` migration step. ```sh go test ./framework/configstore/... ``` Verify that the `calendar_aligned` column is dropped from both `governance_budgets` and `governance_rate_limits` when no FK violations are present, and that a warning is logged (rather than a fatal error) when the drop cannot be completed. ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues N/A ## Security considerations None. The affected columns are unconstrained boolean fields with no auth, secrets, or PII implications. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
## Summary Fixes a boot failure caused by GORM's `Migrator.DropColumn` performing a full SQLite table rebuild, which aborts when pre-existing foreign key violations are present. The migration that drops the legacy `calendar_aligned` columns from `governance_budgets` and `governance_rate_limits` is updated to use raw SQL instead, avoiding the rebuild entirely. ## Changes - Replaced `gorm.Migrator.HasColumn` / `DropColumn` calls in `migrationDropLegacyCalendarAlignedColumns` with raw `ALTER TABLE ... DROP COLUMN IF EXISTS` statements. - Since these are unconstrained boolean columns with no data integrity implications, failures are now logged as warnings rather than returned as errors, preventing a hard boot failure in environments with FK violations. ## Type of change - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test Run the migration against a SQLite database that has pre-existing foreign key violations and confirm the application boots successfully without erroring on the `drop_legacy_calendar_aligned_columns` migration step. ```sh go test ./framework/configstore/... ``` Verify that the `calendar_aligned` column is dropped from both `governance_budgets` and `governance_rate_limits` when no FK violations are present, and that a warning is logged (rather than a fatal error) when the drop cannot be completed. ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues N/A ## Security considerations None. The affected columns are unconstrained boolean fields with no auth, secrets, or PII implications. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable

Summary
Fixes a boot failure caused by GORM's
Migrator.DropColumnperforming a full SQLite table rebuild, which aborts when pre-existing foreign key violations are present. The migration that drops the legacycalendar_alignedcolumns fromgovernance_budgetsandgovernance_rate_limitsis updated to use raw SQL instead, avoiding the rebuild entirely.Changes
gorm.Migrator.HasColumn/DropColumncalls inmigrationDropLegacyCalendarAlignedColumnswith rawALTER TABLE ... DROP COLUMN IF EXISTSstatements.Type of change
Affected areas
How to test
Run the migration against a SQLite database that has pre-existing foreign key violations and confirm the application boots successfully without erroring on the
drop_legacy_calendar_aligned_columnsmigration step.go test ./framework/configstore/...Verify that the
calendar_alignedcolumn is dropped from bothgovernance_budgetsandgovernance_rate_limitswhen no FK violations are present, and that a warning is logged (rather than a fatal error) when the drop cannot be completed.Screenshots/Recordings
N/A
Breaking changes
Related issues
N/A
Security considerations
None. The affected columns are unconstrained boolean fields with no auth, secrets, or PII implications.
Checklist
docs/contributing/README.mdand followed the guidelines