diff options
| author | ivar <i@oiee.no> | 2026-04-23 22:54:31 +0200 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2026-04-23 22:54:31 +0200 |
| commit | 4817e77682fb05288496a6e2db6b1e1c9260aba9 (patch) | |
| tree | e001e1d1ef15cc2e7f3380992f150112686dcf53 /docs/superpowers/specs | |
| parent | 7f40b470a7d42a7674cc74309b210a968291ca23 (diff) | |
| download | iblog-4817e77682fb05288496a6e2db6b1e1c9260aba9.tar.xz iblog-4817e77682fb05288496a6e2db6b1e1c9260aba9.zip | |
Diffstat (limited to 'docs/superpowers/specs')
| -rw-r--r-- | docs/superpowers/specs/2026-04-07-sql-migrations-design.md | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/docs/superpowers/specs/2026-04-07-sql-migrations-design.md b/docs/superpowers/specs/2026-04-07-sql-migrations-design.md deleted file mode 100644 index 8ce8622..0000000 --- a/docs/superpowers/specs/2026-04-07-sql-migrations-design.md +++ /dev/null @@ -1,66 +0,0 @@ -# SQL Migrations Design - -**Date:** 2026-04-07 -**Status:** Approved - -## Goal - -Replace the inline `CREATE TABLE IF NOT EXISTS` block in `internal/db/db.go` with versioned SQL migration files managed by `golang-migrate/migrate`. - -## Constraints - -- Migrations run automatically at startup (inside `db.Open`) — no CLI subcommand needed. -- Migration files are embedded into the binary via `embed.FS`. -- Continue using the existing `modernc.org/sqlite` driver. -- Existing databases can be discarded (clean start acceptable). - -## Migration Files - -New directory `internal/db/migrations/` holds numbered SQL files: - -``` -internal/db/migrations/ - 000001_init.up.sql — full current schema (tables, indexes, FTS5 virtual table) - 000001_init.down.sql — DROP TABLE / DROP INDEX statements in reverse order -``` - -Future schema changes each get their own numbered pair. golang-migrate applies them in order and records applied versions in a `schema_migrations` table it manages automatically. - -## Embedding - -An `//go:embed migrations` directive in `internal/db/db.go` (package `db`) exposes the directory as an `embed.FS` variable `migrationsFS`. - -## Changes to `db.Open` - -After `sql.Open`, the existing inline `Exec` block is removed and replaced with: - -```go -src, err := iofs.New(migrationsFS, "migrations") -// handle err -driver, err := sqlitedriver.WithInstance(sqldb, &sqlitedriver.Config{}) -// handle err -m, err := migrate.NewWithInstance("iofs", src, "sqlite", driver) -// handle err -if err := m.Up(); err != nil && err != migrate.ErrNoChange { - return nil, err -} -``` - -`ErrNoChange` is silently ignored (DB is already at latest version). - -## New Dependencies - -| Package | Purpose | -|---|---| -| `github.com/golang-migrate/migrate/v4` | Core migration engine | -| `github.com/golang-migrate/migrate/v4/database/sqlite` | modernc.org/sqlite driver adapter | -| `github.com/golang-migrate/migrate/v4/source/iofs` | `embed.FS` migration source | - -## File Changes - -| File | Change | -|---|---| -| `internal/db/db.go` | Add `//go:embed migrations`, replace inline Exec with migrate wiring | -| `internal/db/migrations/000001_init.up.sql` | New — current schema | -| `internal/db/migrations/000001_init.down.sql` | New — reverse of init | -| `go.mod` / `go.sum` | Add three golang-migrate packages | |
