Skip to content

v1.data.extensions · extension-stage - #29

Merged
JaimeStill merged 13 commits into
mainfrom
extension-stage
Nov 24, 2026
Merged

JaimeStill merged 13 commits into
mainfrom
extension-stage

Conversation

@JaimeStill

Copy link
Copy Markdown
Contributor

v1.data.extensions · task 1/5 · extension-stage

Summary

  • migrate.Options.Extensions declares the Postgres extensions an application needs, by name
    and in order, with an optional removed flag and no version. The image's default version is
    the only version source.
  • Up checks every declared extension before it activates any, then activates the ones that
    are missing or behind, each in its own transaction, under the migrator's lock. An extension
    the image lacks, or one with no update path to the default, fails before any set runs.
  • After its sets, Up drops each removed declaration with RESTRICT. A dependent column fails
    the run until a set migration removes it.
  • Verify checks extensions before sets. Missing, behind, and removed-but-installed all unwrap
    to ErrPending, so go-database's admin service applies them unchanged.
    Migrator.Extensions(ctx) reports each declaration's state.
  • postgres.Dialect supplies the statements, and pgtest.MigratedWith passes options through.
    Both merge unreleased against sqlate v0.7.0.
  • sqlate is current: marathon 0.24.0 and mise-action v5.3.0.

Core changes

  1. migrate.ExtensionCatalog: the engine's statements, as text, behind the Dialect boundary.
    Why: migrate holds no engine SQL, and postgres still builds against v0.7.0.
    type ExtensionCatalog interface {
        ExtensionState(param string) string // installed, default, update path
        ActivateExtension(name string) []string
        RemoveExtension(name string) string
    }
  2. One classifier gives the verdict for activation, Verify, and Extensions.Pending, so
    the three agree. Why: a pending result in a status report must mean Up has work to do.
  3. Typed errors: *ExtensionError names the extension and wraps ErrExtensionUnavailable,
    *NoUpdatePathError (both versions), or *ExtensionPendingError (→ ErrPending).
  4. Live proofs against postgres:19.0-alpine's hstore:
    • 1.4 is pending, and Up brings it to 1.8;
    • an absent name fails before any set;
    • RESTRICT waits for the dependent column;
    • Reset keeps the extension;
    • two concurrent Up runs activate once.

Verify

mise run check: ✓ build, vet, race tests, lint, and tidy in all 3 modules (GOWORK=off),
sqlint, lint-context, lint-references

  1. mise run acceptance → ok postgres, ok postgres/pgtest, and the stack is torn down.
  2. mise run db:up, then go test -tags integration -count=1 -v -run Live_ ./... in
    postgres/, then mise run db:reset → the five TestLive_Extension…/…ConcurrentUpsActivateOnce
    proofs run and pass.
  3. cd postgres && GOWORK=off go build ./... && GOWORK=off go list -m github.com/standards-lab/sqlate
    → it builds, and the requirement is v0.7.0.
  4. go doc ./migrate ExtensionCatalog → the capability that v0.8.0 makes public.

Decided without you

  1. Activation and Verify treat an extension that is installed but no longer offered as
    unavailable.

  2. Removal reads and drops one declaration at a time, so a failed drop stops before the next
    one is read.

  3. Log lines extension activated (extension, version, from) and extension removed
    (extension, version) mirror migration applied.

  4. A positive Steps activates after its ErrBelowPending refusal, so a refused Steps touches
    no extension.

  5. postgres quotes names with pgx.Identifier.Sanitize. Its var _ migrate.ExtensionCatalog
    assertion lives in the integration-tagged test, the only place the new symbol may appear.

  6. An extension's pending error reads extension "x": migrate: migrations pending: …, because
    behavior 9 makes it unwrap to ErrPending.

  7. No live proof covers a false update path: stock contrib extensions can't stage one, so the
    unit tier proves it, as behavior 15 sets out.

  8. Dropped six decisions that the code and guide now state:

    • plan's declarations, reconcile, and removal lines;
    • extension-stage's capability, verbs, and update-path lines.

    The coordinator's postgres-extensions.md pending edit carries them to principles.

Redirects and escalations

  1. Slice 2: the implementer first counted unavailable and no-path as pending. The session held
    Extensions to the brief's narrow reading: missing, or behind with a path.

Merge danger: one-way door for tag v0.8.0 (migrate's new exported API); the rest is
two-way · blast radius: sqlate only, and postgres is unreleased until postgres/v0.9.0 in
sqlint-extensions · sqlate: merge waits on CI, then marathon ci, then tag v0.8.0

Needs you: none

…ity, and Migrator.Extensions

Options.Extensions declares extensions in order as migrate.Extension
{Name, Removed}, with no version. New refuses an empty or repeated name, and
any declaration on a dialect without ExtensionCatalog, still with no I/O.

ExtensionCatalog is the dialect capability returning statement text, as
Catalog does: ExtensionState(param) (installed, default, update path; no row
reads as neither installed nor offered), ActivateExtension(name) []string
(create if not exists, then update), and RemoveExtension(name) (drop if
exists, RESTRICT). The dialect quotes the name. New binds the state query
once at the dialect's first placeholder.

Migrator.Extensions reads each declaration on the pool without the lock and
returns ExtensionStatus{Name, Removed, Installed, Default, Pending}. Decision:
an active declaration is pending whenever its installed version is not the
default, so an unavailable or no-path extension also reports pending (not
Ready); a removed one is pending while installed.

Error types for the later slices: ExtensionError{Extension, Err} names the
extension and unwraps to ErrExtensionUnavailable, *NoUpdatePathError
(Installed, Default; class ErrNoUpdatePath), or *ExtensionPendingError
(Removed, Installed, Default; class ErrPending).

The guide (docs/features.md) and migrate's doc.go inventory document them.
…ding

An active declaration is pending only when its extension is missing but
offered, or installed behind the default with an update path to it. An
extension the database does not offer, or an installed version with no
update path, is not pending: Installed and Default show its state, and
Verify reports it as its own class. A removed declaration stays pending
while installed, offered or not. Tests cover each case; the guide says so.
Up runs the extension stage after every set's history is checked and
before any set; a positive Steps, on the migrator or a layer, runs it after
ErrBelowPending and before applying. The stage reads every active
declaration on the pinned connection (removed ones are skipped) and refuses
before activating any: no default is an *ExtensionError over
ErrExtensionUnavailable, and an installed version that differs from the
default without an update path (covering one newer than the image's) is an
*ExtensionError over *NoUpdatePathError. A declaration at the default runs
nothing; each missing or older one runs ActivateExtension's statements
through inTx, one transaction per declaration, in declared order, and logs
"extension activated" with extension, version, and from (the installed
version, omitted when missing). An activation failure is an
*ExtensionError over the mapped driver error and stops the run before the
next declaration and every set.

The stage runs inside locked, so Unlocked skips the lock as for sets.
Down, a non-positive Steps, Reset, and Force do not run it.

Unit tests over the scripted driver prove the ordering, the newer-than-
default failure for Up, Migrator.Steps and Layer.Steps, Unlocked, and that
the revert verbs and Force issue no extension statement. The guide, the
Up/Steps/Layer.Steps doc comments, and Options.Logger say so.
Verify reads every extension declaration on the pool, without the lock,
in declared order, before any set, and returns the first fault as an
*ExtensionError naming the extension: missing-but-offered, behind with an
update path, and removed-but-installed are over *ExtensionPendingError
(ErrPending); not offered is over ErrExtensionUnavailable and an installed
version with no update path over *NoUpdatePathError, neither ErrPending.
Layer.Verify and Status stay set-only.

Decisions:
- One unexported classifier, classify, gives the verdict for Verify,
  activateExtensions and Extensions' Pending, so the three cannot drift.
  activateExtensions keeps skipping removed declarations before it.
- A removed declaration's verdict depends only on whether it is
  installed; the default is carried into ExtensionPendingError for the
  message's detail but does not affect the verdict.
- An active declaration installed but no longer offered is
  ErrExtensionUnavailable, the same as activateExtensions already chose.
After every set, Up reads each removed declaration in declared order on
the pinned connection (inside the lock, or without it under Unlocked) and,
where classify reports it pending, runs RemoveExtension in its own
transaction through inTx, logging "extension removed" with the extension
and its installed version. A failing drop (RESTRICT) returns an
*ExtensionError over the dialect-mapped driver error and stops before the
next declaration. A removed declaration not installed, offered or not, runs
no statement; one installed but no longer offered is dropped, as classify
and Verify call it pending.

Decisions:
- Removal reads and drops each declaration in turn rather than reading all
  first, since removal has no refusal class to check up front; a failing
  drop therefore also skips the later declarations' state reads.
- Steps (either sign), Down, Reset, and Force never remove; the revert and
  Force no-statement test now declares a removed extension too.
- Up's, Reset's, both Steps' and Options.Logger's doc comments and the
  guide's Extensions section document removal, RESTRICT, the no-op,
  deleting a declaration, and Reset leaving extensions installed.
…dWith; live proofs and v0.8.0 changelog

postgres.Dialect gains ExtensionState, ActivateExtension, and RemoveExtension
in a new extensions.go that references no migrate symbol, so the module still
builds against sqlate v0.7.0 under GOWORK=off. The compile-time assertion
that it implements migrate.ExtensionCatalog lives in the integration-tagged
extensions_live_test.go.

- The state query reads pg_available_extensions filtered by the bound name;
  the path column is FALSE when nothing is installed, TRUE when installed
  equals default, and otherwise EXISTS over pg_extension_update_paths(name)
  with source = installed, target = default, path IS NOT NULL.
- Names are quoted with pgx.Identifier{name}.Sanitize(), the identifier
  quoting the module already uses (pgtest), since the dialect had no
  quoting helper of its own.
- pgtest.MigratedWith takes migrate.Options; Migrated delegates with empty
  options.
- Live proofs run each case in its own pgtest database with inline Go-string
  migrations, as the existing live tests author theirs.
- Guide, README, postgres and pgtest doc.go, postgres CHANGELOG [Unreleased],
  and the base CHANGELOG's v0.8.0 entry with its compare link.
…lity named as locker is, ErrPending's doc names both details

Consistency and tests-and-docs: Migrator kept a clone of opts.Extensions beside opts; the clone
now lives in opts, read as m.opts.Extensions like Logger and Unlocked, and the capability field
is named extensions as locker names the lock capability. ErrPending's doc comment now names
*ExtensionPendingError, which also unwraps to it.
…nding, not the query's text

Tests that lie (tests-and-docs): the test matched fragments of the implementation's SQL, so it
restated the query rather than proving behavior. It now asserts the seam's contract, the name
bound once at the given parameter; the live proofs cover what the query reads.
@JaimeStill
JaimeStill merged commit 7bd71d3 into main Nov 24, 2026
1 check passed
@JaimeStill
JaimeStill deleted the extension-stage branch November 24, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant