fix(db): make earliest migrations idempotent (0002/0011/0012) - #486
Closed
jonathonbyrdziak wants to merge 1 commit into
Closed
fix(db): make earliest migrations idempotent (0002/0011/0012)#486jonathonbyrdziak wants to merge 1 commit into
jonathonbyrdziak wants to merge 1 commit into
Conversation
The migration runner (DatabaseManager.runMigrations) fails fast: any error in a migration's `up` SQL is rethrown and aborts DB init. Migrations 0002, 0011, and 0012 predate the `IF NOT EXISTS` convention that every migration from 0009 onward follows, so on any install where the tables/columns already exist but aren't recorded in sulla_migrations (pre-tracking installs, restored DBs, or a backfilled/seeded migrations table) they throw 42P07 / duplicate column and brick boot. - 0002: CREATE TABLE agent_awareness -> IF NOT EXISTS - 0011: CREATE TABLE sulla_settings -> IF NOT EXISTS; also fix down migration which dropped the wrong table (`settings` -> `sulla_settings`) - 0012: ADD COLUMN "cast" -> ADD COLUMN IF NOT EXISTS; down -> DROP COLUMN IF EXISTS Verified: all three fixed `up` statements run clean against already-existing objects on the live DB (previously would error). Transpile-checked. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
|
PR opened: #503 (autonomous heartbeat cycle). Fix applied and verified in an isolated worktree off |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DatabaseManager.runMigrationsfails fast — any error in a migration'supSQL is rethrown and aborts DB init (DatabaseManager.ts:138). Migrations 0002, 0011, 0012 are the earliest ones and predate theIF NOT EXISTSconvention that every migration from 0009 onward already follows.On any install where the tables/columns already exist but aren't recorded in
sulla_migrations, these three re-run theirupand throw42P07(duplicate table) / duplicate column — bricking boot. That scenario is exactly the migration-table backfill/seed path under investigation (pre-tracking installs, restored DBs, or a manually seededsulla_migrations).Fix
CREATE TABLE agent_awareness→CREATE TABLE IF NOT EXISTSCREATE TABLE sulla_settings→CREATE TABLE IF NOT EXISTS; also fixes a latent down-migration bug — it droppedsettingsinstead ofsulla_settingsADD COLUMN "cast"→ADD COLUMN IF NOT EXISTS; down →DROP COLUMN IF EXISTSAudit
Swept all 22 registered migrations: these three are the only non-idempotent DDL. 0009/0014/0024 already use
ADD COLUMN IF NOT EXISTS; 0010 indexes useCREATE INDEX IF NOT EXISTS; noCREATE TYPE/enum. Registry legitimately stops at 0028 (CRM 0029–0036 were added then removed infb5e8017d).Verification
tsc --isolatedModules, exit 0) — template literals balanced.upstatements against the live DB where the objects already exist → all succeed as no-ops. Pre-fix these would throw. Idempotency proven.Schema-only, no user data (complies with the no-user-data-in-migrations rule).
🤖 Generated with Claude Code