appdb

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package appdb owns the single SQLite database the HTTP API server uses for OAuth2/MCP storage, the embedded IDP, browser sessions, and user-saved batch-submission templates. Previously each subsystem opened its own SQLite file under LOCAL_DIR, but that meant adding a new feature (templates) silently failed the whole server when its directory wasn't writable, while the OAuth2 DB worked fine. Folding them all into one file removes that asymmetry.

Schema evolution is managed with pressly/goose against the embedded migration files in the migrations/ subdirectory. Add a new numbered file with the standard goose `-- +goose Up` header and Migrate() will pick it up at next startup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, db *sql.DB) error

Migrate runs all pending goose migrations bundled in the migrations/ subdirectory. Idempotent; safe to call on every startup. Returns an error if any migration fails — the caller should refuse to start the server in that case rather than serve a partially-migrated DB.

Goose's default logger writes to log.Default(). We route it through a Writer that drops everything; the API server's structured logger reports the migration outcome via its own log line in NewHandler.

func Open

func Open(path string) (*sql.DB, error)

Open opens (or creates) the SQLite database at path and returns a *sql.DB ready for the various storage layers to share. The file is not migrated yet — the caller must call Migrate before using it.

We pin max-open to 1: SQLite serializes writes anyway, and the schema-create step relies on serial DDL to avoid the "database is locked" symptom that pops up under concurrent writers.

Open does an eager writability check on the parent directory and (when the file already exists) on the file itself. SQLite's pure-Go driver returns the cryptic "out of memory (14)" for any open failure, including "permission denied" and "directory doesn't exist" — which on a misconfigured deployment looks like an allocator problem but is really a filesystem ACL issue. By probing here we surface a real "directory not writable" error before sql.Open lazily tries to write.

Types

This section is empty.

Directories

Path Synopsis
Package seal provides envelope encryption for sensitive columns in the unified application database.
Package seal provides envelope encryption for sensitive columns in the unified application database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL