Documentation
¶
Index ¶
- func ApplyMigrationCatalog(databaseURL string, catalog fs.FS) (bool, error)
- func AsPgxTx(tx DBTX) (pgx.Tx, error)
- func BuildCursorValues(cursor, sortBy string) (pgtype.Text, pgtype.Timestamptz, pgtype.Text, error)
- func EmbeddedMigrationCatalog() (fs.FS, error)
- func EmbeddedMigrationCatalogIdentity() (uint, string, error)
- func FromNullableInt32(i pgtype.Int4) *int32
- func FromNullableInt64(i pgtype.Int8) *int64
- func FromNullableText(t pgtype.Text) *string
- func FromNullableTimestamptz(ts pgtype.Timestamptz) *time.Time
- func InRead[T any](ctx context.Context, txm TransactionManager, ...) (T, error)
- func InTx[T any](ctx context.Context, txm TransactionManager, ...) (T, error)
- func IsForeignKeyViolation(err error) bool
- func IsUniqueViolation(err error, constraintName ...string) bool
- func LatestEmbeddedMigrationVersion() (uint, error)
- func LatestMigrationVersion(migrationNames []string) (uint, error)
- func MigrationCatalogIdentity(files fs.FS, directory string) (uint, string, error)
- func MigrationDatabaseURL(databaseURL, ledger string) (string, error)
- func OptionalSlugToText(s *slug.Slug) pgtype.Text
- func SlugToText(s slug.Slug) pgtype.Text
- func ToNullableInt32(i *int32) pgtype.Int4
- func ToNullableInt64(i *int64) pgtype.Int8
- func ToNullableText(s *string) pgtype.Text
- func ToNullableTimestamptz(ts *time.Time) pgtype.Timestamptz
- func ToText(s string) pgtype.Text
- func ToTimestamptz(ts time.Time) pgtype.Timestamptz
- func WithConsistentSnapshot(ctx context.Context) context.Context
- func WithoutTransaction(ctx context.Context) context.Context
- type DBTX
- type MigrationPreflight
- type MigrationPreflightStatus
- type MigrationState
- type MigrationStateReader
- type SessionLocker
- type TransactionManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyMigrationCatalog ¶
ApplyMigrationCatalog applies one catalog to an explicitly selected ledger URL. Construct databaseURL with MigrationDatabaseURL before calling this function.
func AsPgxTx ¶
AsPgxTx unwraps a DBTX into the concrete pgx transaction type required by libraries that integrate directly with pgx transaction semantics.
func BuildCursorValues ¶
func BuildCursorValues( cursor, sortBy string, ) (pgtype.Text, pgtype.Timestamptz, pgtype.Text, error)
BuildCursorValues parses an encoded cursor into SQLC-friendly typed values.
func EmbeddedMigrationCatalog ¶
EmbeddedMigrationCatalog returns the core catalog compiled into this module version.
func EmbeddedMigrationCatalogIdentity ¶
EmbeddedMigrationCatalogIdentity identifies the catalog compiled into this binary.
func FromNullableInt32 ¶
FromNullableInt32 converts pgtype.Int4 to *int32, returning nil if not valid.
func FromNullableInt64 ¶
FromNullableInt64 converts nullable database identities and revisions.
func FromNullableText ¶
FromNullableText converts pgtype.Text to *string, returning nil if not valid.
func FromNullableTimestamptz ¶
func FromNullableTimestamptz(ts pgtype.Timestamptz) *time.Time
FromNullableTimestamptz converts pgtype.Timestamptz to *time.Time, returning nil if not valid.
func InRead ¶
func InRead[T any]( ctx context.Context, txm TransactionManager, fn func(ctx context.Context, db DBTX) (T, error), ) (T, error)
InRead executes fn with a non-transactional database handle and returns the function result without forcing callers to manage an outer return variable.
func InTx ¶
func InTx[T any]( ctx context.Context, txm TransactionManager, fn func(ctx context.Context, tx DBTX) (T, error), ) (T, error)
InTx executes fn in a transaction and returns the function result without forcing callers to manage an outer return variable.
func IsForeignKeyViolation ¶
IsForeignKeyViolation checks if the error is a foreign key constraint violation
func IsUniqueViolation ¶
IsUniqueViolation checks if the error is a unique constraint violation. If constraintName is provided, it also checks if the constraint name matches.
func LatestEmbeddedMigrationVersion ¶
LatestEmbeddedMigrationVersion returns the highest up migration version embedded in the running binary.
func LatestMigrationVersion ¶
LatestMigrationVersion returns the highest numeric version from up migration filenames.
func MigrationCatalogIdentity ¶
MigrationCatalogIdentity matches the raw-byte catalog identity used by release manifests.
func MigrationDatabaseURL ¶
MigrationDatabaseURL selects the same public ledger used by readiness checks.
func OptionalSlugToText ¶
OptionalSlugToText converts a *slug.Slug to pgtype.Text, returning invalid if nil.
func SlugToText ¶
SlugToText converts a slug.Slug to pgtype.Text.
func ToNullableInt32 ¶
ToNullableInt32 converts *int32 to pgtype.Int4, returning invalid pgtype.Int4 if nil.
func ToNullableInt64 ¶
func ToNullableText ¶
ToNullableText converts *string to pgtype.Text, returning invalid pgtype.Text if nil.
func ToNullableTimestamptz ¶
func ToNullableTimestamptz(ts *time.Time) pgtype.Timestamptz
ToNullableTimestamptz converts *time.Time to pgtype.Timestamptz, returning invalid if nil.
func ToTimestamptz ¶
func ToTimestamptz(ts time.Time) pgtype.Timestamptz
ToTimestamptz converts time.Time to pgtype.Timestamptz.
func WithConsistentSnapshot ¶
WithConsistentSnapshot requests one database view for a multi-query plan. Callers must select this before opening their outer unit of work.
Types ¶
type MigrationPreflight ¶
type MigrationPreflight struct {
// contains filtered or unexported fields
}
MigrationPreflight checks that the target database schema matches the running release before the application serves traffic.
func NewMigrationPreflight ¶
func NewMigrationPreflight(database MigrationStateReader, ledger string, requiredVersion uint) (*MigrationPreflight, error)
NewMigrationPreflight checks one explicitly selected release catalog and ledger.
func (*MigrationPreflight) Check ¶
func (p *MigrationPreflight) Check(ctx context.Context) error
Check verifies that the database migration state is safe for this release.
func (*MigrationPreflight) Status ¶
func (p *MigrationPreflight) Status(ctx context.Context) (MigrationPreflightStatus, error)
Status loads and evaluates migration state for operator startup and readiness checks.
type MigrationPreflightStatus ¶
type MigrationPreflightStatus struct {
Ready bool
CurrentVersion uint
RequiredVersion uint
Reason string
}
MigrationPreflightStatus describes whether a database matches this release's migration contract without exposing database connection or query details.
func EvaluateMigrationPreflight ¶
func EvaluateMigrationPreflight( state MigrationState, requiredVersion uint, ) (MigrationPreflightStatus, error)
EvaluateMigrationPreflight compares database migration metadata to the release-required version and rejects every ambiguous state.
type MigrationState ¶
MigrationState is the database migration state recorded by golang-migrate.
func ReadMigrationState ¶
func ReadMigrationState( ctx context.Context, database MigrationStateReader, ledger string, ) (MigrationState, error)
ReadMigrationState reads golang-migrate metadata without exposing migration table details outside the postgres package.
type MigrationStateReader ¶
MigrationStateReader is the narrow pgx query boundary needed by migration preflight checks.
type SessionLocker ¶
type SessionLocker interface {
WithLock(context.Context, string, func(context.Context) error) (bool, error)
}
SessionLocker holds an advisory lock without keeping a transaction open during external work.
func NewSessionLocker ¶
func NewSessionLocker(pool *pgxpool.Pool) SessionLocker
type TransactionManager ¶
type TransactionManager interface {
// RunInTx executes fn inside a database transaction.
// If fn returns an error the transaction is rolled back; otherwise it is committed.
// A panic rolls back the owned transaction and propagates to the caller.
RunInTx(ctx context.Context, fn func(ctx context.Context, tx DBTX) error) error
// RunRead executes fn against a read handle without opening a transaction.
// When the context already carries a transaction, RunRead reuses it so nested
// service calls remain inside the caller's unit of work.
RunRead(ctx context.Context, fn func(ctx context.Context, db DBTX) error) error
}
TransactionManager abstracts database unit-of-work access. Services depend on this interface instead of *pgxpool.Pool directly, making them testable without a real database connection.
func NewTransactionManager ¶
func NewTransactionManager(pool *pgxpool.Pool) TransactionManager
NewTransactionManager creates a TransactionManager backed by a pgxpool.Pool.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package abusecontrols persists shared HTTP abuse-control windows.
|
Package abusecontrols persists shared HTTP abuse-control windows. |
|
Package credentialrekey exposes operator-only ciphertext census and replacement.
|
Package credentialrekey exposes operator-only ciphertext census and replacement. |
|
Package pipelinecreations persists proposals for pipelines not yet imported from Git.
|
Package pipelinecreations persists proposals for pipelines not yet imported from Git. |
|
Package pipelinesinkeffects persists durable pipeline sink side-effect decisions.
|
Package pipelinesinkeffects persists durable pipeline sink side-effect decisions. |
|
Package proofobservations persists the backend-owned Proof observation ledger.
|
Package proofobservations persists the backend-owned Proof observation ledger. |
|
Package repositorysetups persists resumable project repository setup state.
|
Package repositorysetups persists resumable project repository setup state. |