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
44 changes: 43 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,47 @@ module only; the `postgres` and `sqlint` sub-modules each keep their own.

## [Unreleased]

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

The migrator manages database extensions: a program declares them by name, and `Up` activates
them at the image's default version before any set and removes the ones declared removed after
every set.

### Added

- `migrate.Extension` and `migrate.Options.Extensions`, the declarations: each a distinct,
non-empty `Name` with no version, since the version is the default the database offers, and a
`Removed` flag for an extension the migrator drops instead of activating. `New` refuses an
empty or repeated name, and any declaration on a dialect without the capability. Deleting a
declaration only stops the migrator from managing the extension; it is never dropped.
- `migrate.ExtensionCatalog`, the dialect capability that returns the engine's statements as
text: `ExtensionState(param)`, the query that reads an extension's installed version, the
default version the database offers, and whether an update path leads from one to the other;
`ActivateExtension(name)`, the statements that create the extension and update it to its
default; and `RemoveExtension(name)`, the statement that drops it with `RESTRICT`.
- `Migrator.Extensions(ctx)`, which reads an `ExtensionStatus` per declaration, in declared
order, on the pool and without the lock: `Name`, `Removed`, `Installed`, `Default`, and
`Pending`. An active declaration is pending while its extension is missing but offered, or
installed behind the default with an update path to it; a removed one while it is still
installed.
- The extension stage in `Up` and a positive `Steps`, on the migrator or on a layer. Inside the
run's lock, after every set's history is checked, every active declaration is checked before
any is activated, and each missing or older one is activated in its own transaction, in
declared order, before any set, logged as `extension activated`. One already at its default
runs no statement.
- Removal in `Up` alone: after every set, each removed declaration still installed is dropped
in its own transaction, in declared order, logged as `extension removed`. An object still
depending on the extension fails the run with the driver's error mapped through the dialect,
and a later set migration that drops the object lets the next `Up` remove it. `Steps`, `Down`,
`Reset`, and `Force` never remove, and `Reset` leaves every extension installed.
- `Verify` checks every declaration before any set, without the lock, with the verdicts `Up`
and `Extensions` reach.
- The error types: `ExtensionError`, naming the extension, over `ErrExtensionUnavailable` (an
extension the database does not offer), `ErrNoUpdatePath` (`NoUpdatePathError`, an installed
version with no update path to the default, naming both), or `ErrPending`
(`ExtensionPendingError`, a declaration the database does not match yet), or over the mapped
driver error of a failed activation or removal.

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

A transaction's configuration is the standard library's `*sql.TxOptions`, passed as a trailing
Expand Down Expand Up @@ -282,7 +323,8 @@ experiment's library packages.
- `sqltest`, the scripted `database/sql` driver every consumer's unit tier runs over: `Open`,
`Recorder`, `Response`, and the stub `Dialect`.

[Unreleased]: https://github.com/standards-lab/sqlate/compare/v0.7.0...HEAD
[Unreleased]: https://github.com/standards-lab/sqlate/compare/v0.8.0...HEAD
[v0.8.0]: https://github.com/standards-lab/sqlate/compare/v0.7.0...v0.8.0
[v0.7.0]: https://github.com/standards-lab/sqlate/compare/v0.6.1...v0.7.0
[v0.6.1]: https://github.com/standards-lab/sqlate/compare/v0.6.0...v0.6.1
[v0.6.0]: https://github.com/standards-lab/sqlate/compare/v0.5.0...v0.6.0
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ Three conventions the library keeps are stricter than a reader might expect:
- `header` reads the `--|` declaration header of a `.sql` file.
- `query` compiles authored statements against the pattern catalog and binds them to typed
values: rows, projections with request directives, and guards.
- `migrate` versions a schema over authored SQL under the engine's lock, and replaces a
third-party migration dependency.
- `migrate` versions a schema over authored SQL, and reconciles the extensions an application
declares, under the engine's lock, and replaces a third-party migration dependency.
- `sqltest` is the scripted `database/sql` driver for hermetic tests.
- `postgres` (sub-module) is the PostgreSQL dialect: placeholders, error classification, the
advisory lock, and the engine's native forms. Its `pgtest` package gives an integration test
its own throwaway database, migrated or empty, dropped when the test ends.
advisory lock, the extension statements, and the engine's native forms. Its `pgtest` package
gives an integration test its own throwaway database, migrated or empty, dropped when the test
ends.
- `sqlint` (sub-module) is the conventions linter as a package, with the command at
`sqlint/cmd/sqlint`.

Expand Down
4 changes: 2 additions & 2 deletions context/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ express.
([header/doc.go](../header/doc.go)).
- **query** (built): compiles authored statements against the pattern catalog and binds them to
typed handles ([query/doc.go](../query/doc.go)).
- **migrate** (built): versions a schema over authored SQL under the engine's lock
([migrate/doc.go](../migrate/doc.go)).
- **migrate** (built): versions a schema over authored SQL, and reconciles the extensions an
application declares, under the engine's lock ([migrate/doc.go](../migrate/doc.go)).
- **sqltest** (built): the scripted `database/sql` driver for hermetic tests
([sqltest/doc.go](../sqltest/doc.go)).
- **postgres** (built): the PostgreSQL dialect sub-module, with `pgtest` for integration tests'
Expand Down
146 changes: 137 additions & 9 deletions context/goals/v1.data.extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,153 @@

## Tasks

1. [ ] extension-stage
1. [x] extension-stage
2. [ ] sqlint-extensions
3. [ ] pgvector-sql
4. [ ] pgvector-go
5. [ ] principles

## Task brief · extension-stage

**Problem**

An application can't tell sqlate's migrator which Postgres extensions its schema needs. Today an
extension is either installed by hand or written into an ordinary migration with up and down
scripts. Those scripts pile up one per upgrade and have no honest down for a version that has no
downgrade script. The goal needs the migrator to reconcile each declared extension to the version
the image ships, ahead of every set and under the migrator's lock, so that starting replicas take
turns activating. A typed failure must come before any set runs, and `Verify` and a status report
must expose a mismatch, so go-database's admin service applies it unchanged.

**Behaviors**

1. `migrate.Options.Extensions` lists declarations in order. Each has a name and a removed flag,
and no version. `New` refuses an empty or duplicate name. It also refuses any declarations
when the dialect lacks the extension capability, and it still does no I/O.
2. The extension capability is a new migrate interface that returns statement text, as `Catalog`
does. It returns:
- a state query bound to the extension name, giving the installed version (none when not
installed), the image's default version (none when the image doesn't offer the extension),
and whether an update path runs from the installed version to the default;
- the activation statements: create the extension if it doesn't exist, then update it to its
default;
- the removal statement: drop the extension if it exists, with RESTRICT.

The dialect quotes the name.
3. `Up` checks every set's history and then the extensions. It checks every active declaration
before activating any of them. If an extension isn't available in the image, the run fails
with a typed error naming it. The run also fails if the installed version differs from the
default and no update path leads to the default, which covers an installed version newer than
the image's. That error names the extension and both versions. Either failure comes before any
activation and before any set.
4. A declaration whose installed version already equals the default runs no statement, so a
pre-installed database passes under an unprivileged role. A missing or older extension is
activated, each declaration in its own transaction, in declared order, and each activation is
logged.
5. A positive `Steps`, on the migrator or on a layer, runs the same check and activation after its
existing refusals and before applying anything. It removes nothing.
6. After its sets, `Up` removes each removed declaration in declared order, each in its own
transaction, logging each drop. If a dependent object is left behind, RESTRICT fails the run
with the driver's error, mapped through the dialect. A removed declaration whose extension
isn't installed, or isn't available, is a no-op.
7. Deleting a declaration only stops the migrator from managing it and never drops the extension.
`Down`, `Reset`, and `Force` skip the stage, and `Reset` leaves extensions installed.
8. With `Unlocked`, the stage runs without the lock, as the sets do.
9. `Verify` checks extensions before sets, on the pool and without the lock. An active
declaration that is missing or behind the default fails with a typed error that unwraps to
`ErrPending`. So does a removed declaration that is still installed. An unavailable extension,
or one with no update path, fails with its own class, not `ErrPending`. `Layer.Verify` and
`Status` stay set-only.
10. `Migrator.Extensions(ctx)` reads each declaration's state in declared order, on the pool and
without the lock. Each entry reports the name, the removed flag, the installed version, the
image's default version, and whether the declaration is pending: missing or behind for an
active declaration, still installed for a removed one. An unavailable extension shows an empty
default version and is not an error.
11. Every typed error names the extension. `errors.Is` classifies it as `ErrExtensionUnavailable`,
`ErrNoUpdatePath`, or `ErrPending`, and `errors.As` reaches the detail.
12. `postgres.Dialect` implements the capability:
- the state query reads `pg_available_extensions` and `pg_extension_update_paths`;
- activation is `CREATE EXTENSION IF NOT EXISTS` then `ALTER EXTENSION … UPDATE`;
- removal is `DROP EXTENSION IF EXISTS … RESTRICT`.

It references no new migrate symbol outside integration-tagged code, so the postgres module
still builds against sqlate v0.7.0 when the workspace file is off.
13. `pgtest.MigratedWith(t, env, prefix, opts, sets...)` is `Migrated` with the caller's
`migrate.Options`. `Migrated` becomes `MigratedWith` with empty options.
14. The live proofs use the integration image's contrib extensions:
- hstore pre-installed at 1.4 makes `Verify` unwrap to `ErrPending` and `Extensions` report
it pending; after `Up` it is at 1.8 and `Verify` passes;
- a name the image lacks fails `Up` before any set and leaves no history row;
- a removed hstore with a dependent column fails `Up`, and once a set migration drops the
column the same `Up` drops hstore;
- `Reset` leaves hstore installed;
- two concurrent `Up` runs both succeed with one activation.
15. The unit tier, over the scripted driver, covers what the image can't stage: an installed
version newer than the default with no update path fails before any activation and before
any set.
16. The guide documents the stage, `Extensions`, the new errors, the capability, and
`MigratedWith`. The base changelog records v0.8.0, and postgres's changelog records its
additions under Unreleased.

**Test seams**
- `migrate.Migrator` over the scripted `database/sql` driver, with a test dialect that implements
the extension capability (behaviors 1–11 and 15).
- `pgtest.MigratedWith` and `migrate.Migrator` against the integration PostgreSQL, under the
integration tag and the committed workspace (behaviors 12–14).

**Slices**
1. Upgrade sqlate: marathon (claude-plugins) 0.22.0 → 0.24.0 and jdx/mise-action v5.2.10 →
v5.3.0. Done when `mise run currency` exits 0 and the check passes.
2. Declarations and the capability: the `Options.Extensions` declaration, `New`'s validation, the
capability interface, the extension error classes, and `Migrator.Extensions` reporting, with
unit tests and the guide.
3. Activation in `Up` and positive `Steps`: check-all-then-activate, the failures before any
activation or set, one transaction per activation, logging, and `Unlocked`. Includes the
newer-than-image unit case and the guide.
4. `Verify` reports extensions before sets: pending activation and pending removal unwrap to
`ErrPending`, and unavailable or no-path fail as their own classes. Unit tests and the guide.
5. Removal at the end of `Up`, with `Down`, `Reset`, and `Force` skipping the stage. Unit tests
and the guide.
6. postgres: the capability's statements with unit tests of their text, `pgtest.MigratedWith`,
the live proofs in behavior 14, the postgres changelog under Unreleased, the base changelog's
v0.8.0 entry, and the guide.

**Out of scope**

- No extension version declared in Go, no history table, no schema option: an extension installs
where the session's default schema puts it.
- No `CASCADE` on create or drop, and no drop when a declaration is deleted.
- Shipped sets declaring extensions.
- pgvector, its module, the canonical image's pgvector build and its currency line, sqlint's
`extensions` key, and go-database's `admin.Status` field.
- Moving postgres onto v0.8.0 and releasing `postgres/v0.9.0`, which sqlint-extensions does.

**Door**

One-way for the `v0.8.0` tag: once pushed, migrate's new exported API is public at that version
(the `Options.Extensions` declaration, the capability interface, `Migrator.Extensions`, and the
error classes). Everything else stays two-way until `postgres/v0.9.0`: postgres's capability
methods and `pgtest.MigratedWith` merge unreleased, and so do the tests and the guide.

**Release**

`v0.8.0`

## Decisions

- plan: The image is an extension's sole version source: `postgres:19.0-alpine` with each extension
built from source, pgvector pinned by `ARG PGVECTOR_VERSION`. Rejected: pgvector/pgvector's
Debian images, PGDG on Debian, and a version declared in Go.
- plan: Declarations live in `migrate.Options.Extensions` (name, optional removed state, no
version); the stage runs before every set under the migrator's lock, each in its own transaction,
in declared order. Rejected: an application-owned bottom set of up/down migrations.
- plan: The stage reconciles against `pg_available_extensions` with no history table; a mismatch
makes `Verify` unwrap to `ErrPending`; an unavailable version, or an installed one newer than the
image's with no path down, fails before any set runs.
- plan: A removed declaration runs `DROP EXTENSION IF EXISTS x RESTRICT` after the sets; deleting a
declaration never drops; Reset leaves extensions installed.
- plan: Shipped migration sets declare no extensions; only the application does.
- plan: sqlint's `extensions` key; a listed module exports forms, or `forms = []` with a `reason`,
or is refused. No sqlint check against `Options.Extensions`.
- plan: Module paths `sqlate/postgres/pgvector` and `go-database/postgres/pgvector`; the latter uses
pgvector-go's root module over `database/sql` and depends on the former's metric table.
- extension-stage: A removed declaration still installed is pending: `Verify` unwraps to
`ErrPending` and `Extensions` marks it pending, so `admin.Status` reports it not `Ready`.
- extension-stage: Releases `v0.8.0` alone. postgres's capability and `pgtest.MigratedWith` merge
unreleased against v0.7.0; sqlint-extensions' upgrade slice moves postgres onto v0.8.0 and
releases `postgres/v0.9.0` before pgvector-sql needs it.

## Pending edits

Expand All @@ -38,3 +161,8 @@
- coordinator · `context/postgres-extensions.md`: delete it once `principles` promotes it, and
remove its `context/README.md` entry and the pointers in `data-intelligence.md` and
`migration-sets.md`.
- coordinator · `roadmap/v1.data.extensions.toml`: sqlint-extensions' summary adds moving postgres
onto sqlate v0.8.0 and releasing `postgres/v0.9.0`.
- coordinator · `context/postgres-extensions.md`: the check fails on any installed version with no
update path to the image's default (read through `pg_extension_update_paths`), not only a newer
one; a migrate dialect capability supplies the standard pair.
Loading