feat: initial sqlite store

This commit is contained in:
juancwu 2026-05-06 00:16:39 +00:00
commit 9918c9918f
10 changed files with 560 additions and 6 deletions

View file

@ -0,0 +1,38 @@
package sqlite
import (
"context"
"database/sql"
"embed"
"fmt"
"git.juancwu.dev/juancwu/pase/store"
)
//go:embed migrations/*.sql
var migrationsFS embed.FS
// Migrate applies all pending migrations to db using the SQLite dialect.
// It is safe to call repeatedly; already-applied migrations are skipped.
//
// Run from a single instance at startup. There is no advisory locking; if you
// need it, gate the call behind your own coordination primitive.
func Migrate(ctx context.Context, db *sql.DB) error {
migrations, err := store.LoadMigrations(migrationsFS, "migrations")
if err != nil {
return fmt.Errorf("pase/sqlite: load migrations: %w", err)
}
m := &store.Migrator{
DB: db,
Dialect: store.SQLiteDialect{},
Migrations: migrations,
// SQLite's TEXT timestamp convention. INTEGER PK is implicit ROWID alias.
CreateTableSQL: `CREATE TABLE IF NOT EXISTS pase_schema_migrations (
version INTEGER PRIMARY KEY,
name TEXT NOT NULL,
applied_at TEXT NOT NULL
)`,
}
return m.Migrate(ctx)
}