postgres

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package postgres is the production controlplane.Database adapter, backed by Postgres running in the cluster (ADR-0012). It implements the deploy-record seam (ADR-0007): the durable history of releases and the rollback handles, independent of cluster state. Schema changes are applied by embedded goose migrations on startup, gated to single-minor-step upgrades (ADR-0013).

It uses the pgx driver through the standard database/sql interface (not pgxpool, not the maintenance-mode lib/pq), so one *sql.DB serves both the migrations and the app. It lives under controlplane/ (not controlplane/internal) so cmd/burrowd and the managed module can wire it; it is licensed Apache-2.0 (LICENSING.md, ADR-0033).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a Postgres-backed controlplane.Database.

func Open

func Open(ctx context.Context, dsn string) (*Store, error)

Open connects to the database at dsn and verifies the connection. The caller closes the Store with Close. It does not apply the schema; call Migrate for that.

func (*Store) Addon

func (s *Store) Addon(ctx context.Context, name string) (controlplane.AddonInfo, error)

Addon returns the add-on with the given name, or ErrNotFound. The returned info has Ready false — readiness is probed live, never read from the registry.

func (*Store) Addons

func (s *Store) Addons(ctx context.Context) ([]controlplane.AddonInfo, error)

Addons returns all registered add-ons, name order. Each row has Ready false — readiness is a live property, probed by the caller, not stored.

func (*Store) AppEnv

func (s *Store) AppEnv(ctx context.Context, app string) (map[string]string, error)

AppEnv returns the non-secret environment store for app (ADR-0028). An app with no env yields an empty map and no error.

func (*Store) AppendAudit

func (s *Store) AppendAudit(ctx context.Context, e controlplane.AuditEntry) error

AppendAudit appends one audit row (ADR-0027). The log is append-only: there is only this INSERT and the Audit SELECT — no update or delete path. The store assigns id.

func (*Store) Audit

Audit returns audit rows matching filter, newest first, capped by filter.Limit (a default when unset). The filter clauses are optional and ANDed; an empty filter returns the latest rows up to the cap.

func (*Store) Close

func (s *Store) Close() error

Close releases the database connections.

func (*Store) CreateEnvironment added in v0.7.0

func (s *Store) CreateEnvironment(ctx context.Context, name, namespace string) error

CreateEnvironment registers a named environment mapping name to namespace (ADR-0035 phase 2). The name is the primary key, so a duplicate is rejected: the INSERT ... ON CONFLICT DO NOTHING affects no rows, which is reported as an ErrInvalid-wrapped duplicate error.

func (*Store) DeleteAddon

func (s *Store) DeleteAddon(ctx context.Context, name string) error

DeleteAddon removes the add-on row with the given name, or ErrNotFound if no such row exists.

func (*Store) DeleteReleases

func (s *Store) DeleteReleases(ctx context.Context, app string) error

DeleteReleases removes every release record for app. Deleting the releases of an app that has none is a no-op (no RowsAffected check) — absence is fine.

func (*Store) GetBackup

func (s *Store) GetBackup(ctx context.Context, id string) (controlplane.Backup, error)

GetBackup returns the backup with the given id, or ErrNotFound.

func (*Store) GetEnvironment added in v0.7.0

func (s *Store) GetEnvironment(ctx context.Context, name string) (controlplane.Environment, error)

GetEnvironment returns the registered environment with the given name, or ErrNotFound.

func (*Store) LatestRelease

func (s *Store) LatestRelease(ctx context.Context, app string) (controlplane.Release, error)

func (*Store) ListBackups

func (s *Store) ListBackups(ctx context.Context, app string) ([]controlplane.Backup, error)

ListBackups returns recorded backups, newest first. An empty app lists every app's backups; a non-empty app restricts to that app. No matches yields an empty slice and no error.

func (*Store) ListEnvironments added in v0.7.0

func (s *Store) ListEnvironments(ctx context.Context) ([]controlplane.Environment, error)

ListEnvironments returns the registered environments ordered by name (ADR-0035 phase 2). The synthesized `default` environment is not stored here; the engine prepends it.

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context, appVersion string) error

Migrate brings the database schema up to date and records appVersion as the version that last migrated it. It first enforces the single-minor-step upgrade gate (ADR-0013): if the database was last migrated by a different version, the upgrade must be exactly one minor step forward within the same major, or Migrate refuses before changing anything. Migrations are applied under a Postgres advisory lock, so concurrent control-plane replicas do not race. Migrate is safe to call on every startup; with no pending migrations it only re-stamps the version.

func (*Store) Policy

func (s *Store) Policy(ctx context.Context) (controlplane.Policy, error)

Policy returns the current guardrail policy: the built-in defaults with any stored guardrail dispositions overlaid (ADR-0020). An empty table yields DefaultPolicy.

func (*Store) Provider

func (s *Store) Provider(ctx context.Context, name string) (controlplane.Provider, error)

Provider returns the provider with the given name, or ErrNotFound.

func (*Store) Providers

func (s *Store) Providers(ctx context.Context) ([]controlplane.Provider, error)

Providers returns all configured providers, name order.

func (*Store) RecordBackup

func (s *Store) RecordBackup(ctx context.Context, b controlplane.Backup) error

RecordBackup persists a new backup row (ADR-0032). burrowd records it pending before starting the backup Job, then SetBackupStatus moves it to completed/failed when the Job finishes. An existing row with the same id is overwritten. The row names the app, the on-PVC path, and the status — never a credential.

func (*Store) Release

func (s *Store) Release(ctx context.Context, id string) (controlplane.Release, error)

func (*Store) Releases

func (s *Store) Releases(ctx context.Context, app string) ([]controlplane.Release, error)

func (*Store) SaveAddon

func (s *Store) SaveAddon(ctx context.Context, a controlplane.AddonInfo) error

SaveAddon upserts an add-on in the registry by name (ADR-0025). It records the non-secret registry entry — type, mode, backend, where it lives, and the capabilities it serves. Ready is a live property of the cluster and is never persisted; it is probed at list time.

func (*Store) SaveProvider

func (s *Store) SaveProvider(ctx context.Context, p controlplane.Provider) error

SaveProvider upserts a provider in the registry by name (ADR-0023). It records only the non-secret registry entry; the token lives in the burrow-credentials Secret.

func (*Store) SaveRelease

func (s *Store) SaveRelease(ctx context.Context, r controlplane.Release) error

func (*Store) SetAppEnv

func (s *Store) SetAppEnv(ctx context.Context, app, key, value string) error

SetAppEnv upserts one env key for app.

func (*Store) SetBackupStatus

func (s *Store) SetBackupStatus(ctx context.Context, id string, status controlplane.BackupStatus, sizeBytes int64) error

SetBackupStatus updates a recorded backup's status and size (the Job-finished transition). Setting the status of an unknown backup id returns ErrNotFound.

func (*Store) SetGuardrail

func (s *Store) SetGuardrail(ctx context.Context, code controlplane.GuardrailCode, disp controlplane.Disposition) error

SetGuardrail upserts one guardrail's disposition.

func (*Store) UnsetAppEnv

func (s *Store) UnsetAppEnv(ctx context.Context, app, key string) error

UnsetAppEnv removes one env key for app. Removing a key that is not set is a no-op.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL