new-migration

Solid

Add or change decant's SQLite schema safely. Use when adding a column, table, index, or FTS change to the archive, when bumping LATEST_SCHEMA_VERSION, when a SchemaDriftError appears on open, or when reviewing a change that touches src/db.ts, src/schema.sql, or src/schema-manifest.ts.

API & Backend 59 stars 3 forks Updated yesterday Apache-2.0

Install

View on GitHub

Quality Score: 81/100

Stars 20%
59
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Adding a schema migration Read `src/db.ts` around the newest migration before writing anything. The archive baseline is v21 and the current value lives at `src/db.ts:24`. ## The rule that matters most **A migration is frozen the moment it is committed to a branch.** A dogfooding archive may already have run it, and re-running an edited version is not possible. If review asks for a change to a migration that is already committed, add a new version rather than editing the old one. Never edit a committed migration, even on an unmerged branch. This is not theoretical. Migration 11 was once run in an uncommitted form against the live archive, which left a stray `session.context_compaction_count` column that the fingerprint gate then rejected on open. Repairing it took a guarded migration of its own rather than a rebuild. ## Steps 1. **Write the migration guarded.** Follow the existing style in `src/db.ts`. Use the `hasTable` and `hasColumn` helpers so a partially migrated archive converges instead of throwing, then stamp it. ```ts if (version < 22) { if (hasTable(db, "session") && !hasColumn(db, "session", "my_column")) { db.exec("ALTER TABLE session ADD COLUMN my_column INTEGER"); } db.query( "INSERT INTO schema_migrations (version, applied_at) VALUES (22, datetime('now'))", ).run(); } ``` `assertSchemaMatchesBaseline` runs after the migration chain, so a migration that leaves the database disagreeing with `src/s...

Details

Author
dosu-ai
Repository
dosu-ai/decant
Created
2 months ago
Last Updated
yesterday
Language
TypeScript
License
Apache-2.0

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category