Documentation
¶
Overview ¶
Package store is the persistent-state layer for compliancekit's serve-mode daemon. Phase 1 lands the schema + migration runner + the Store abstraction that phase 2's Postgres backend will re-implement.
The schema lives under migrations/ as plain SQL files. Both the sqlite backend (phase 1) and the postgres backend (phase 2) consume the same files; portable SQL is enforced by review + integration tests against both engines.
IDs are TEXT (uuid4) for portability across SQLite + Postgres; timestamps are TEXT (RFC-3339) for the same reason. See migrations/0001_initial.sql for the full schema rationale.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsMissingMigration ¶
Sentinel for callers that want to detect the "fresh DB" path.
Types ¶
type Driver ¶
type Driver string
Driver identifies the underlying engine. Lets repository code branch on dialect when SQLite + Postgres diverge (e.g. JSONB vs TEXT JSON, RETURNING, LISTEN/NOTIFY).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the abstract handle every daemon component consumes. Both the sqlite and postgres backends satisfy this interface. Phase 6/7 (REST API) and phase 11 (UI shell) layer Repositories on top of this in their respective packages.
func OpenPostgres ¶
OpenPostgres returns a Store backed by jackc/pgx/v5/stdlib (the canonical Go PG driver, used via the standard database/sql interface so repository code stays driver-agnostic).
dsn accepts the libpq DSN forms pgx understands:
postgres://user:pass@host:port/db?sslmode=require postgresql://user:pass@host:port/db host=... user=... password=... dbname=... sslmode=...
Connection-pool sizing is set conservatively for the v1.3 workload (the daemon's reads dominate; writes happen via the worker pool from phase 8). Operators with high-throughput needs can tune via future Config knobs.
func OpenSQLite ¶
OpenSQLite returns a Store backed by modernc.org/sqlite (pure Go, no CGO). path may be a filesystem path, ":memory:" for tests, or "file::memory:?cache=shared" for cross-connection in-memory state.
PRAGMA settings applied at open time:
journal_mode=WAL — concurrent reads + single-writer with no
blocking. Required for the v1.3 worker pool
which writes while the UI reads.
foreign_keys=ON — SQLite defaults to OFF; the schema relies on
CASCADE / SET NULL semantics so this must be
on for every connection.
synchronous=NORMAL — durability/perf trade matched to WAL; safe
against power loss (just may rewind to the
last fsync).
busy_timeout=5000 — five-second wait for the writer lock before
ERR; tests + concurrent webhook receivers
need this.
func (*Store) DB ¶
DB returns the underlying *sql.DB for code paths that need direct SQL access (migrations, raw queries, transactions). Repository packages should prefer adding methods on Store over reaching for DB() — but the escape hatch is here when needed.
func (*Store) MigrateUp ¶
MigrateUp applies every pending migration in order. Idempotent — re-running after every migration has been applied is a no-op. Errors fail fast; the partial state of a failed migration is left in place (we don't roll back) so the operator can inspect.
Concurrent calls are serialized via SQLite's writer lock; on Postgres we take a session-scoped advisory lock so two daemon processes pointed at the same DB can't race the migration apply.