Documentation
¶
Index ¶
- Constants
- Variables
- func DSN(cfg config.PostgresConfig) string
- func DriverFromConfig(cfg config.Config) string
- func IsUniqueViolation(err error) bool
- func MigrationsFSForConfig(cfg config.Config, embedded fs.FS) (fs.FS, error)
- func Open(ctx context.Context, cfg config.Config) (*pgxpool.Pool, error)
- func OpenPostgres(ctx context.Context, cfg config.PostgresConfig) (*pgxpool.Pool, error)
- func OpenPostgresDSN(ctx context.Context, dsn string) (*pgxpool.Pool, error)
- func ParseUUID(id string) (pgtype.UUID, error)
- func ParseUUIDOrEmpty(id string) pgtype.UUID
- func RunMigrate(logger *slog.Logger, cfg config.PostgresConfig, migrationsFS fs.FS, ...) error
- func RunMigrateConfig(logger *slog.Logger, cfg config.Config, migrationsFS fs.FS, command string, ...) error
- func RunMigrateTarget(logger *slog.Logger, target MigrationTarget, migrationsFS fs.FS, ...) error
- func SetDefaultTeamOnConnect(ctx context.Context, conn *pgx.Conn) error
- func TextToString(value pgtype.Text) string
- func TimeFromPg(value pgtype.Timestamptz) time.Time
- type MigrationStatus
- type MigrationTarget
Constants ¶
const (
DriverPostgres = "postgres"
)
Variables ¶
var ( ErrNotFound = errors.New("database record not found") ErrLastActiveAdmin = errors.New("team must retain at least one active admin") // ErrCommitOutcomeUnknown means a transaction's COMMIT acknowledgement was // lost. Callers that would perform destructive compensation must reconcile // an idempotency/publication key on a fresh connection first. ErrCommitOutcomeUnknown = errors.New("database transaction commit outcome is unknown") )
Functions ¶
func DSN ¶
func DSN(cfg config.PostgresConfig) string
DSN builds a PostgreSQL connection string from config.
func DriverFromConfig ¶
func IsUniqueViolation ¶
IsUniqueViolation reports whether err is a PostgreSQL UNIQUE constraint violation.
func MigrationsFSForConfig ¶
func OpenPostgres ¶
func OpenPostgresDSN ¶
OpenPostgresDSN opens a pool from a raw libpq DSN with the default-team AfterConnect hook installed. Single-team test harnesses use this so their pools bind the team GUC exactly like production.
func ParseUUIDOrEmpty ¶
ParseUUIDOrEmpty converts a string UUID to pgtype.UUID, returning an invalid UUID if the string is empty or unparsable.
func RunMigrate ¶
func RunMigrate(logger *slog.Logger, cfg config.PostgresConfig, migrationsFS fs.FS, command string, args []string) error
RunMigrate applies or rolls back database migrations. The migrationsFS should contain .sql files at its root (not in a subdirectory). Supported commands: "up", "down", "version", "force N".
func RunMigrateConfig ¶
func RunMigrateTarget ¶
func SetDefaultTeamOnConnect ¶
SetDefaultTeamOnConnect is a pgxpool AfterConnect hook that binds the singleton team GUC (memoh.team_id) at the session level. It is exported so single-team test harnesses can install it on their own pools, matching the production connection setup.
func TextToString ¶
TextToString returns the string value of pgtype.Text, or "" when invalid.
func TimeFromPg ¶
func TimeFromPg(value pgtype.Timestamptz) time.Time
TimeFromPg converts a pgtype.Timestamptz to time.Time.
Types ¶
type MigrationStatus ¶
func ReadMigrationStatus ¶
func ReadMigrationStatus(cfg config.PostgresConfig, migrationsFS fs.FS) (MigrationStatus, error)
func ReadMigrationStatusTarget ¶
func ReadMigrationStatusTarget(target MigrationTarget, migrationsFS fs.FS) (MigrationStatus, error)
type MigrationTarget ¶
func MigrationTargetFromConfig ¶
func MigrationTargetFromConfig(cfg config.Config) (MigrationTarget, error)