Documentation
¶
Overview ¶
Package pgschema provisions the Postgres tables of the SDK storage packages at startup (queue, auditlog/auditpg, translation/translationpg, settings) and derives the advisory-lock keys of the SDK (lock, partition).
Ensure runs the idempotent DDL of a package in a transaction under an advisory lock keyed by "skit.<pkg>.schema", so the replicas booting at once serialize instead of racing on CREATE TABLE:
err := pgschema.Ensure(ctx, log, db, "auditlog", Schema()) // db is a *dbx.DB
Key hashes a name into an advisory-lock key with FNV-1a. The hash never changes: the replicas of two versions of a service must agree on the key.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ensure ¶
Ensure applies the idempotent ddl of the package pkg once, safely, at service startup. It runs ddl inside a transaction holding a Postgres transaction-scoped advisory lock keyed by "skit.<pkg>.schema", so when several replicas boot together they serialize on the lock and concurrent CREATE ... IF NOT EXISTS statements do not race ("tuple concurrently updated" / duplicate-relation errors). The lock releases when the transaction ends — commit, rollback, or a dropped connection — so it cannot leak. ddl runs as written, without :name parsing.
func Key ¶
Key derives a stable Postgres advisory-lock key from name using FNV-1a, so a package claims a collision-resistant key without hand-picking a magic integer that might clash with the application's own advisory locks — advisory locks share one namespace per database. The hash never changes: replicas of two versions of a service must agree on the key of a name.
Types ¶
This section is empty.