Repository navigation
v1.data.extensions · extension-stage - #29
Merged
Merged
Conversation
…; log the task brief
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
v1.data.extensions · task 1/5 · extension-stage
Summary
migrate.Options.Extensionsdeclares the Postgres extensions an application needs, by nameand in order, with an optional removed flag and no version. The image's default version is
the only version source.
Upchecks every declared extension before it activates any, then activates the ones thatare 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.
Updrops each removed declaration with RESTRICT. A dependent column failsthe run until a set migration removes it.
Verifychecks extensions before sets. Missing, behind, and removed-but-installed all unwrapto
ErrPending, so go-database's admin service applies them unchanged.Migrator.Extensions(ctx)reports each declaration's state.postgres.Dialectsupplies the statements, andpgtest.MigratedWithpasses options through.Both merge unreleased against sqlate v0.7.0.
Core changes
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.
Verify, andExtensions.Pending, sothe three agree. Why: a pending result in a status report must mean
Uphas work to do.*ExtensionErrornames the extension and wrapsErrExtensionUnavailable,*NoUpdatePathError(both versions), or*ExtensionPendingError(→ErrPending).postgres:19.0-alpine's hstore:Upbrings it to 1.8;Resetkeeps the extension;Upruns activate once.Verify
mise run check: ✓ build, vet, race tests, lint, and tidy in all 3 modules (GOWORK=off),sqlint, lint-context, lint-references
mise run acceptance→ok postgres,ok postgres/pgtest, and the stack is torn down.mise run db:up, thengo test -tags integration -count=1 -v -run Live_ ./...inpostgres/, thenmise run db:reset→ the fiveTestLive_Extension…/…ConcurrentUpsActivateOnceproofs run and pass.
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.go doc ./migrate ExtensionCatalog→ the capability thatv0.8.0makes public.Decided without you
Activation and
Verifytreat an extension that is installed but no longer offered asunavailable.
Removal reads and drops one declaration at a time, so a failed drop stops before the next
one is read.
Log lines
extension activated(extension, version, from) andextension removed(extension, version) mirror
migration applied.A positive
Stepsactivates after itsErrBelowPendingrefusal, so a refusedStepstouchesno extension.
postgres quotes names with
pgx.Identifier.Sanitize. Itsvar _ migrate.ExtensionCatalogassertion lives in the integration-tagged test, the only place the new symbol may appear.
An extension's pending error reads
extension "x": migrate: migrations pending: …, becausebehavior 9 makes it unwrap to
ErrPending.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.
Dropped six decisions that the code and guide now state:
The coordinator's
postgres-extensions.mdpending edit carries them toprinciples.Redirects and escalations
Extensionsto 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 istwo-way · blast radius: sqlate only, and postgres is unreleased until
postgres/v0.9.0insqlint-extensions · sqlate: merge waits on CI, then
marathon ci, then tagv0.8.0Needs you: none