migration fix for calendar aligned - #3553
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughRefactors SQLite migration helpers in framework/configstore/migrations.go: reorders legacy budget models and docs, adds a generic hasColumn(tx, table, column) helper, and updates migrateCalendarAlignedToBudgetsAndRateLimitsTable to use hasColumn and raw ALTER TABLE statements to add missing calendar_aligned columns. ChangesSQLite Migration Helpers Refactoring
Possibly Related PRs
Suggested Reviewers
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 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 |
|
|
f6dd628 to
8871cc5
Compare
f3deede to
44b56a9
Compare
Confidence Score: 5/5Safe to merge — the new The change is narrowly scoped to one migration function. All previously identified concerns (silent error suppression, missing schema filter in the information_schema query, duplicate doc comments) have been addressed in this revision. The No files require special attention. Important Files Changed
Reviews (3): Last reviewed commit: "Apply suggestions from code review" | Re-trigger Greptile |
There was a problem hiding this comment.
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 `@framework/configstore/migrations.go`:
- Around line 252-267: The hasColumn function currently swallows errors from the
schema introspection query (tx.Raw(...).Scan(&count).Error) and returns false,
which is ambiguous; change hasColumn(tx *gorm.DB, table, column string) to
return (bool, error), propagate and return the actual error from
tx.Raw(...).Scan(&count).Error instead of returning false, and update any
callers of hasColumn to handle the error (abort migration or surface the error)
rather than treating a false as “column missing”; keep the existing Dialector
switch and query construction (including the sqlite and default queries) but
ensure errors are returned up the call chain.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bb927236-3ab9-4328-8aac-abda49b8057e
📒 Files selected for processing (1)
framework/configstore/migrations.go
99e4d37 to
806a322
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
framework/configstore/migrations.go (1)
252-263: ⚡ Quick winReuse
sqliteTableHasColumnin the SQLite branch.This adds a second SQLite schema-introspection path next to
sqliteTableHasColumn, which makes future fixes easy to miss in one place.♻️ Suggested simplification
func hasColumn(tx *gorm.DB, table, column string) (bool, error) { + switch tx.Dialector.Name() { + case "sqlite": + return sqliteTableHasColumn(tx, table, column) + } + var count int64 - var q string - switch tx.Dialector.Name() { - case "sqlite": - q = `SELECT COUNT(*) FROM pragma_table_info(?) WHERE name = ?` - default: - q = `SELECT COUNT(*) FROM information_schema.columns WHERE table_name = ? AND column_name = ? AND table_schema = current_schema()` - } + q := `SELECT COUNT(*) FROM information_schema.columns WHERE table_name = ? AND column_name = ? AND table_schema = current_schema()` if err := tx.Raw(q, table, column).Scan(&count).Error; err != nil { return false, err } return count > 0, 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 252 - 263, The SQLite branch in hasColumn duplicates schema-introspection logic instead of reusing the existing sqliteTableHasColumn helper; replace the sqlite-specific query path in hasColumn with a call to sqliteTableHasColumn(tx, table, column) and return its (bool, error) result so errors are preserved and there is a single canonical implementation to maintain; ensure the call matches sqliteTableHasColumn's signature and that the default (non-sqlite) branch keeps the existing information_schema query and error propagation.
🤖 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 252-263: The SQLite branch in hasColumn duplicates
schema-introspection logic instead of reusing the existing sqliteTableHasColumn
helper; replace the sqlite-specific query path in hasColumn with a call to
sqliteTableHasColumn(tx, table, column) and return its (bool, error) result so
errors are preserved and there is a single canonical implementation to maintain;
ensure the call matches sqliteTableHasColumn's signature and that the default
(non-sqlite) branch keeps the existing information_schema query and error
propagation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fe47c60d-3d13-4d5d-a5fe-4ad5c03f7eff
📒 Files selected for processing (1)
framework/configstore/migrations.go
Merge activity
|
## Summary Replaces GORM's `Migrator.HasColumn` / `AddColumn` calls in the `migrate_calendar_aligned` migration with raw SQL, and adds doc comments to all legacy budget migration helpers. The GORM migrator approach was unreliable across dialects; the new `hasColumn` helper queries `pragma_table_info` (SQLite) or `information_schema.columns` (all other databases) directly, and column addition is done via a plain `ALTER TABLE ... ADD COLUMN` statement. ## Changes - Added a `hasColumn` helper that checks for a column's existence using dialect-aware raw SQL instead of the GORM migrator API. - Replaced `mig.HasColumn` / `mig.AddColumn` calls in `migrateCalendarAlignedToBudgetsAndRateLimitsTable` with `hasColumn` and raw `ALTER TABLE` statements for both `governance_budgets.calendar_aligned` and `governance_rate_limits.calendar_aligned`. - Added doc comments to all legacy budget migration types and helper functions (`legacyBudgetVirtualKey`, `legacyBudgetVirtualKeyProviderConfig`, `legacyBudgetTeam`, `sqliteColumnInfo`, `legacyBudgetColumnModel`, `currentBudgetOwnerModel`, `quoteSQLiteIdentifier`, `sqliteTableColumns`, `sqliteTableHasColumn`). ## 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 ```sh go test ./framework/configstore/... ``` Run against both a SQLite and a supported relational database to confirm the `calendar_aligned` column is added correctly on a fresh migration and that re-running the migration is idempotent (column already exists case is skipped without error). ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues N/A ## Security considerations No auth, secrets, or PII implications. Raw SQL identifiers in the new helper use parameterised queries, so there is no SQL injection risk. ## 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
Replaces GORM's
Migrator.HasColumn/AddColumncalls in themigrate_calendar_alignedmigration with raw SQL, and adds doc comments to all legacy budget migration helpers. The GORM migrator approach was unreliable across dialects; the newhasColumnhelper queriespragma_table_info(SQLite) orinformation_schema.columns(all other databases) directly, and column addition is done via a plainALTER TABLE ... ADD COLUMNstatement.Changes
hasColumnhelper that checks for a column's existence using dialect-aware raw SQL instead of the GORM migrator API.mig.HasColumn/mig.AddColumncalls inmigrateCalendarAlignedToBudgetsAndRateLimitsTablewithhasColumnand rawALTER TABLEstatements for bothgovernance_budgets.calendar_alignedandgovernance_rate_limits.calendar_aligned.legacyBudgetVirtualKey,legacyBudgetVirtualKeyProviderConfig,legacyBudgetTeam,sqliteColumnInfo,legacyBudgetColumnModel,currentBudgetOwnerModel,quoteSQLiteIdentifier,sqliteTableColumns,sqliteTableHasColumn).Type of change
Affected areas
How to test
go test ./framework/configstore/...Run against both a SQLite and a supported relational database to confirm the
calendar_alignedcolumn is added correctly on a fresh migration and that re-running the migration is idempotent (column already exists case is skipped without error).Screenshots/Recordings
N/A
Breaking changes
Related issues
N/A
Security considerations
No auth, secrets, or PII implications. Raw SQL identifiers in the new helper use parameterised queries, so there is no SQL injection risk.
Checklist
docs/contributing/README.mdand followed the guidelines