@memory/database.go @db/ current hardcode migration in code, it's better use altas generate migration and use altas to migration instead of hard code migrate in code. explore and make a plan
Assistant· claude-opus-4-6
Let me explore the current setup first.
Assistant· claude-opus-4-6
Let me explore the current setup thoroughly.
Assistant· claude-opus-4-6
Now let me check how OpenDB and migrate are used, and look at the mise tasks for any existing atlas setup.
Assistant· claude-opus-4-6
Good, I have a clear picture now. Here's my analysis and plan, V:
Current State
Hardcoded migrations in memory/database.go: a hand-rolled migrate() function using PRAGMA user_version with a switch statement (v0→v1→v2)
Schema source of truth: db/schemas/tables/*.sql (7 table files) with an Atlas-style main.sql import file
Atlas already installed via mise (v0.36.0) and MigrationsFS is already embedded in db/embed.go — but db/migrations/ is empty and Atlas isn't actually used at runtime
OpenDB in memory/database.go is the single entry point (called from memory/engine.go)
sqlc generates query code from the same schema files
Problems with Current Approach
Each new schema change requires manually writing ALTER TABLE statements in Go code
The switch/case migration ladder doesn't scale — every version needs a new Go function
isDuplicateColumnError is a fragile string-match hack
The schema files and the Go migration code can drift out of sync
No way to generate migration SQL diffs automatically
Proposed Plan
Phase 1: Atlas Configuration
Create atlas.hcl in project root with:
env "local" pointing to SQLite with db/schemas/main.sql as the desired schema
env "migration" for generating versioned migration files into db/migrations/
Add mise tasks for Atlas workflow:
mise run atlas:diff — generates a new migration from schema changes
mise run atlas:apply — applies pending migrations (dev use)
Phase 2: Generate Initial Baseline Migration
Run atlas migrate diff --env migration to generate the baseline migration from the current schema
Run atlas migrate hash to create the atlas integrity file
This populates db/migrations/ with the initial .sql file + atlas.sum
Phase 3: Replace Runtime Migration in Go
Add atlas-go SDK dependency: ariga.io/atlas-go-sdk/atlasexec (or use the lighter embedded approach with atlasexec)
Alternative: Use Atlas's golang-migrate compatible format and apply migrations with database/sql directly by reading from MigrationsFS
Simplest approach: Use Atlas only for generating migrations (CLI tool), and apply them at runtime with a lightweight Go migration runner that reads SQL files from MigrationsFS — no new Go dependency needed
Rewrite memory/database.go:
Replace the hardcoded migrate() switch with a file-based migration runner
Create a migrations table to track applied versions (replacing PRAGMA user_version)
Read .sql files from db.MigrationsFS in order, skip already-applied ones, execute new ones in a transaction
Do you want a Go dependency on the Atlas SDK for runtime migration, or prefer the zero-dependency approach (Atlas CLI for generation only, simple Go runner for applying SQL files from the embedded FS)?
I'd recommend the zero-dependency approach — it keeps the binary lean, Atlas stays a dev-only tool, and the runtime migration logic is ~50 lines of straightforward Go.