Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v7.0.1

- uses: jdx/mise-action@v5.2.10
- uses: jdx/mise-action@v5.3.0

- name: mise run check
run: mise run check
28 changes: 26 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@
All notable changes to `github.com/standards-lab/go-database` are documented here. The format
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the module adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). This changelog covers the base module
only; the `postgres` sub-module keeps its own.
only; the `postgres` and `postgres/pgvector` sub-modules each keep their own.

## [Unreleased]

## [v0.13.0] - 2026-11-24

### Added

- `admin.Status.Extensions` (`extensions` in JSON), one `admin.ExtensionStatus` per extension
declaration the migrator manages, in declared order: its name, whether it is removed, the
installed version and the database's default version (each empty when absent), and whether it
is pending. The list is empty, never nil, when no extension is declared.
- `Service.Start` logs each pending extension as `extension pending; applying`, with its name and
its installed and default versions, beside the pending sets before it applies them.

### Changed

- `Status.Ready`, and the service's readiness with it, is false while any extension declaration
does not match the database: one pending, one the database does not offer, or one with no
update path from its installed version to the default.
- `migrate.ErrExtensionUnavailable` and `migrate.ErrNoUpdatePath`, from `Service.Start`,
`Service.Verify`, and the schema verbs, wrap in `admin.ErrConflict` with the migrate sentinel
still in the chain, and mark the service not ready.
- The `sqlate` requirement is v0.8.0, which adds database extension declarations to `migrate`:
`migrate.Options.Extensions`, `Migrator.Extensions`, the `migrate.ExtensionCatalog` dialect
capability, and the `ErrExtensionUnavailable` and `ErrNoUpdatePath` sentinels.

## [v0.12.0] - 2026-11-11

The sweeper's configuration is a trailing Options struct, not variadic option functions:
Expand Down Expand Up @@ -396,7 +419,8 @@ depends on the standard library and `github.com/standards-lab/go-core v0.1.0`.
so an unknown field or trailing content in a curated seed file fails the decode. Idempotency
stays in the load function's SQL, where the conflict target is known.

[Unreleased]: https://github.com/standards-lab/go-database/compare/v0.12.0...HEAD
[Unreleased]: https://github.com/standards-lab/go-database/compare/v0.13.0...HEAD
[v0.13.0]: https://github.com/standards-lab/go-database/compare/v0.12.0...v0.13.0
[v0.12.0]: https://github.com/standards-lab/go-database/compare/v0.11.0...v0.12.0
[v0.11.0]: https://github.com/standards-lab/go-database/compare/v0.10.0...v0.11.0
[v0.10.0]: https://github.com/standards-lab/go-database/compare/v0.9.0...v0.10.0
Expand Down
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# go-database

go-database is an SQL infrastructure library for Standards Lab's Go Elemental standard. It
holds four things:
holds five things:

- the connection pool, with its configuration, lifecycle, and readiness
- the database admin service, built over the `sqlate` library
- the sweeper, which runs a service's reclaimers
- the Postgres provider
- the pgvector module, which resolves a configured distance metric

`github.com/standards-lab/go-database` is the base module, holding the `database` package at its
root and `admin` and `sweep` beside it. `github.com/standards-lab/go-database/postgres` is a
nested sub-module that pins the driver and is released on its own tags.
`github.com/standards-lab/go-database/postgres/pgvector` is a nested sub-module that requires
sqlate's `postgres/pgvector` and is released on its own tags.

## Standard

Expand All @@ -22,6 +25,11 @@ principles:

- The base module depends on the standard library, `go-core`, and `sqlate`; the driver enters a
consumer's graph only through the `postgres` sub-module, imported once at the composition root.
- The `postgres/pgvector` sub-module depends on the standard library and sqlate's
`postgres/pgvector`. Only its integration tier requires pgvector-go, the base module, and
sqlate's `postgres`, so its `go.mod` lists them as test-only requirements. Like a provider, it
is imported only by the composition root, the migrations, and the packages the application's
design documentation declares.
- [`sqlate`](https://github.com/standards-lab/sqlate) owns the SQL layer above the pool:
statements, sessions, transactions, and the dialect. The composition root wraps the pool this
library constructs with `sqlate.Wrap` and the engine's dialect from `sqlate/postgres`, and the
Expand All @@ -46,17 +54,38 @@ principles:
It imports no reclaimer; a library's reclaimer satisfies its interface.
- `postgres` is the PostgreSQL provider: it constructs the pool over pgx's `database/sql` adapter
from the configuration block.
- `pgvector` resolves the pgvector distance metric an application's configuration names into
sqlate's metric table, and its package doc shows pgvector-go's vector types used directly.

## Development

The repository uses a Go workspace and [mise](https://mise.jdx.dev):

```
mise run check # build, vet, format, fix, tidy, test, and lint every module, then lint-context and lint-references; writes nothing
mise run currency # report requirements, Go, tools, and actions behind their latest
mise run currency # report requirements, Go, tools, actions, images, and Dockerfile source ARGs behind their latest
mise run upgrade # upgrade every module's go directive and requirements, and the tools, to their latest
mise run db:up # build and start the compose PostgreSQL and wait until it is healthy
mise run db:down # stop PostgreSQL, discarding its data
mise run integration # run the integration tier against the running stack
mise run acceptance # db:up, integration, then db:down whatever the result; prints the stack's log on failure
```

`compose.yml` runs PostgreSQL with pgvector on port 5438; `POSTGRES_PORT` moves it, and
`GO_DATABASE_DSN` in `mise.toml` follows it. The service builds from
`compose/postgres/Dockerfile`, a copy of sqlate's canonical PostgreSQL image: its `FROM` line is
the one image pin, `ARG PGVECTOR_VERSION` the extension's, and `mise run currency` reports either
when it trails its latest. The stack is a test-only harness that keeps its data on tmpfs, so every
`db:up` starts empty.

The `postgres/pgvector` module's integration tier sits behind the `integration` build tag and
runs against the stack: `admin.Start` activating a declared `vector` extension, a `vector`
column round-tripping pgvector-go values and NULL, and each metric's operator ordering a
nearest-neighbor query. Each test makes its own throwaway database through sqlate's
`postgres/pgtest`. The tier runs on a developer's machine only, through `mise run acceptance`,
and needs Docker; CI runs `mise run check`, which vets, fixes, and lints the tier with its tag
but runs only the unit tier.

## License

[Apache License 2.0](LICENSE).
10 changes: 5 additions & 5 deletions STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
The judgement calls the standards-reviewer applies to go-database, beyond what `mise run check` enforces.

- A change that alters documented behavior updates the README and the affected `doc.go` in the same change.
- `architecture/standards/go-elemental/principles/dependencies.md`: the base module's and `postgres`'s `go.mod`.
- `architecture/standards/go-elemental/principles/tests-and-docs.md`: the doc.go inventory of `database`, `admin`, `sweep` and `postgres`, and the unit tier over sqlate's `sqltest`, the `database` tests' stub driver and the `postgres` tests' in-test `pgproto3` server.
- `architecture/standards/go-elemental/principles/topology-and-naming.md`: the base module with `database`, `admin` and `sweep`, and the `postgres` provider sub-module and its tags.
- `architecture/standards/go-elemental/principles/release-and-ci.md`: the check, currency and upgrade tasks over `GO_MODULES`, which matches `go.work`'s use-list, and a changelog per module, `CHANGELOG.md` and `postgres/CHANGELOG.md`.
- `architecture/standards/go-elemental/principles/dependencies.md`: the base module's, `postgres`'s and `postgres/pgvector`'s `go.mod`; `postgres/pgvector`'s requires sqlate's `postgres/pgvector`.
- `architecture/standards/go-elemental/principles/tests-and-docs.md`: the doc.go inventory of `database`, `admin`, `sweep`, `postgres` and `pgvector`, and the unit tier over sqlate's `sqltest`, the `database` tests' stub driver and the `postgres` tests' in-test `pgproto3` server; and `postgres/pgvector`'s integration tier, behind the `integration` tag, over sqlate's `postgres/pgtest` against the compose stack, run locally by `mise run acceptance`.
- `architecture/standards/go-elemental/principles/topology-and-naming.md`: the base module with `database`, `admin` and `sweep`, the `postgres` provider sub-module and its tags, and the `postgres/pgvector` sub-module and its tags.
- `architecture/standards/go-elemental/principles/release-and-ci.md`: the check, currency and upgrade tasks over `GO_MODULES`, which matches `go.work`'s use-list, the compose stack of `compose.yml` and `compose/postgres`, a test-only harness on tmpfs, and a changelog per module, `CHANGELOG.md`, `postgres/CHANGELOG.md` and `postgres/pgvector/CHANGELOG.md`.
- `architecture/standards/go-elemental/principles/lifecycle-and-context.md`: `DB`'s `Start`, `Shutdown` and `Ready`, and `admin.Service`'s `Start` and `Ready`; the constructors' panics on an unfinalized `Config` or a missing pool, and `postgres.New`'s error on a reserved option.
- `architecture/standards/go-elemental/principles/baseline-standards.md`: `Config`'s pool-size and timeout defaults, and `admin`, which takes every migration set, seed set, catalog and registry from its consumer.
- `architecture/standards/go-elemental/principles/utc-times.md`: `postgres.New`'s connections, which scan `timestamptz` in UTC.
- `architecture/standards/go-elemental/principles/construction-and-execution.md`: `sweep.New` takes its configuration as a trailing `sweep.Options` whose zero value keeps the defaults.
- `architecture/principles/service-tiers.md`: `DB.Conn`, `Config.Options`, and the `postgres` provider.
- `architecture/principles/validation-first.md`: `Config.Finalize`, and `admin`'s verbs, which refuse an argument outside their domain before any I/O.
- `architecture/principles/validation-first.md`: `Config.Finalize`, and `admin`'s verbs, which refuse an argument outside their domain before any I/O, and `pgvector.ParseMetric`, which refuses an unknown metric name before any I/O.
- `architecture/principles/context-architecture.md`: the README and each `doc.go`.
- `architecture/principles/comments.md`: every comment.
19 changes: 11 additions & 8 deletions admin/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
// The Service is not a Stopper: it holds nothing the pool's shutdown does
// not release.
//
// [Service.Start] applies pending migrations, verifies the seeder, and
// applies the configured seed set, idempotently at every start. A dirty
// set, or a history a set does not carry, fails startup, and a failed Start
// stops the process, so an operator repairs the schema through the verbs of
// another replica or starts a process against the corrected database.
// [Service.Start] applies pending extensions and migrations, verifies the
// seeder, and applies the configured seed set, idempotently at every start.
// A dirty set, a history a set does not carry, or a declared extension the
// database does not offer or cannot update to its default fails startup,
// and a failed Start stops the process, so an operator repairs the schema
// through the verbs of another replica or starts a process against the
// corrected database.
// [Service.Ready] reports the schema alone, as the last operation that
// determined it found it; once Start has succeeded, a not-ready service
// re-verifies at most once per five seconds. A true Ready is not
Expand All @@ -71,10 +73,11 @@
// The schema verbs run the migrator's function of their name, and the seed
// verbs the seeder's:
//
// - [Service.Verify] checks every set's history and the seeder's
// statements.
// - [Service.Verify] checks every extension declaration, every set's
// history, and the seeder's statements.
// - [Service.Status] reads the schema into a [Status]: one [SetStatus]
// per set, and one [MigrationInfo] per migration.
// per set, one [MigrationInfo] per migration, and one
// [ExtensionStatus] per extension declaration.
// - [Service.Up] applies every set's pending migrations.
// - [Service.Down] reverts, [Service.Steps] applies or reverts, and
// [Service.Force] sets the history version of the set each names.
Expand Down
24 changes: 20 additions & 4 deletions admin/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ type Pool struct {
WaitDuration time.Duration `json:"wait_duration"`
}

// Status is the schema's state: Ready when every set is clean and current,
// and each set's state in declared order.
// Status is the schema's state: Ready when every set is clean and current
// and every extension declaration matches the database, each set's state,
// and each extension declaration's state, in declared order.
type Status struct {
Ready bool `json:"ready"`
Sets []SetStatus `json:"sets"`
Ready bool `json:"ready"`
Sets []SetStatus `json:"sets"`
Extensions []ExtensionStatus `json:"extensions"`
}

// SetStatus is one migration set's state.
Expand All @@ -50,6 +52,20 @@ type SetStatus struct {
Migrations []MigrationInfo `json:"migrations"`
}

// ExtensionStatus is one extension declaration's state. A declaration
// matches the database when its extension is installed at the default
// version the database offers, or, when Removed, is not installed; Pending
// marks a mismatch Up resolves, so an extension the database does not offer,
// or one with no update path to the default, is neither matched nor
// pending.
type ExtensionStatus struct {
Name string `json:"name"`
Removed bool `json:"removed"`
Installed string `json:"installed"` // empty when not installed
Default string `json:"default"` // empty when the database does not offer it
Pending bool `json:"pending"`
}

// MigrationInfo describes one migration of a set.
type MigrationInfo struct {
Version int `json:"version"`
Expand Down
Loading