Skip to content

SQLite: enable WAL mode and add migration tracking table #48

Description

@koinsaari

Background

Two related gaps in internal/db/db.go:

  1. WAL mode not enabled. CLAUDE.md documents "WAL-friendly pragmas" but the DSN only sets busy_timeout and foreign_keys. Without journal_mode=WAL, concurrent reads and writes block each other under load.

  2. Migrations re-run on every startup. applyMigrations iterates and executes every .sql file unconditionally. This works only as long as all migrations are idempotent (IF NOT EXISTS etc.), which is not enforced. A non-idempotent migration (e.g. ALTER TABLE, data patch) will corrupt on the second startup.

What changes

  • Add _pragma=journal_mode(WAL) to the DSN
  • Add SetMaxOpenConns(1) after sql.Open to serialize writers (correct for WAL with database/sql)
  • Add a schema_migrations tracking table and skip already-applied migrations in applyMigrations

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions