Documentation
¶
Overview ¶
Package devdb manages the development database the type oracle runs against: a user-supplied DSN, or an auto-managed disposable container. See docs/design/04-type-oracle.md §2.
Index ¶
- func Acquire(ctx context.Context, cfg Config) (*pgx.Conn, func(), error)
- func AcquireDSN(ctx context.Context, cfg Config) (string, func(), error)
- func AcquireMySQL(ctx context.Context, cfg Config) (*gomysqlclient.Conn, func(), error)
- func AcquireMySQLDSN(ctx context.Context, cfg Config) (string, func(), error)
- func AcquireSQLite(ctx context.Context, cfg Config) (*sqlite3.Conn, func(), error)
- type Config
- type DestructiveResetError
- type Detected
- type VersionMismatchError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Acquire ¶
Acquire connects to (or starts) the dev database, verifies the version pin, and applies the schema. The returned cleanup is never nil and terminates the container (when one was started) after closing the connection.
func AcquireDSN ¶
AcquireDSN starts (or reuses) the dev database, verifies the version pin, applies the schema, and returns the DSN — for callers that need to hand the database to a subprocess. cleanup is never nil.
func AcquireMySQL ¶
AcquireMySQL connects to (or starts) the MySQL dev database, verifies the version pin, and applies the schema. DSNs use the go-sql-driver format (user:pass@tcp(host:port)/dbname). The database is disposable by contract: when SchemaSQL is non-empty, every table in the target database is dropped before the schema is applied.
func AcquireMySQLDSN ¶
AcquireMySQLDSN is AcquireMySQL for callers that need to hand the database to a subprocess; it returns the go-sql-driver DSN.
func AcquireSQLite ¶
AcquireSQLite opens (or creates) the SQLite dev database — fully in-process, nothing external. DSN is a database file path; empty means a fresh file in a private temp directory. The database is disposable by contract: when SchemaSQL is non-empty, every table and view is dropped before the schema is applied.
Types ¶
type Config ¶
type Config struct {
// DSN, when set, is used as-is instead of starting a container.
// The referenced database MUST be disposable: whenever SchemaSQL
// is non-empty, sqletch resets the public schema (DROP SCHEMA
// public CASCADE) before applying it, so repeated runs are
// idempotent. Never point this at a database you care about.
//
// Because the DSN comes from sqletch.yaml — repo-controlled, so a
// cloned project could aim it at a database the developer cares
// about — a user-supplied DSN does NOT reset by default: Acquire
// returns *DestructiveResetError unless AllowDestructive is set. A
// database sqletch provisioned itself (empty DSN → a fresh
// container or temp file) is disposable by construction and always
// resets.
DSN string
// AllowDestructive clears the user-supplied-DSN reset guard above:
// the caller (a person passing --allow-destructive on the command
// line) has confirmed the database at DSN is disposable, so sqletch
// may drop and recreate its schema. It is ignored when DSN is empty.
AllowDestructive bool
// ServerVersion is the pinned version prefix (e.g. "16" or
// "16.4"); it selects the container image and is validated as a
// dotted prefix of whatever we connect to (see versionPrefixMatch).
ServerVersion string
// SchemaSQL is executed in order after connecting (plain SQL —
// schema files are read by the caller).
SchemaSQL []string
// Detected, when non-nil, receives what Acquire learned by
// connecting — facts no caller can compute offline. It is filled
// in before the schema is applied; on an error return its contents
// are undefined. Callers that do not care leave it nil, and then
// the extra round trip is skipped unless the version pin needs it.
Detected *Detected
}
type DestructiveResetError ¶
type DestructiveResetError struct {
Server string // display name, e.g. "PostgreSQL", "MySQL", "SQLite"
}
DestructiveResetError signals that Acquire declined to reset a user-supplied database's schema because AllowDestructive (--allow-destructive) was not set — the clone-and-run guard (SQLETCH204 at the CLI layer). Like VersionMismatchError it is shared by all three dialects, so Server names the engine actually targeted; the disposable-reset contract is not PostgreSQL-specific. The DSN is deliberately NOT carried here: it may embed credentials, and the diagnostic points at database.dsn in the config rather than echoing the string back.
func (*DestructiveResetError) Error ¶
func (e *DestructiveResetError) Error() string
type Detected ¶
type Detected struct {
// ServerVersion is the raw string the engine reported, e.g.
// "16.4 (Debian 16.4-1.pgdg120+1)", "8.0.36-log", "3.50.4".
ServerVersion string
}
Detected is the connected server's own account of itself, reported back to callers that asked for it via Config.Detected.
type VersionMismatchError ¶
type VersionMismatchError struct {
Pinned, Actual string
Server string // display name, e.g. "PostgreSQL", "MySQL", "SQLite"
}
VersionMismatchError signals that the connected server does not match the pinned server_version (SQLETCH200 at the CLI layer). Every dialect's Acquire returns it, so Server names the engine actually connected to — the message is not PostgreSQL-specific.
func (*VersionMismatchError) Error ¶
func (e *VersionMismatchError) Error() string