Help us shape the future of Go! Take the 2026 Go Developer Survey

postgres

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package postgres implements the repository interfaces on Postgres.

This is the only place in the project that contains SQL (invariant 5).

Index

Constants

View Source
const TestDatabaseSuffix = "_test"

TestDatabaseSuffix is what a database has to be called before TruncateAll will empty it.

A suffix rather than one fixed name, so a second checkout or a throwaway database for one run is not locked out — `schmetterpause_test`, `schmetterpause_pr162_test`, anything that says out loud what it is for.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, dsn string) error

Migrate applies all pending migrations. The migrations are embedded in the binary, so the image brings them along itself.

func MigrateDown

func MigrateDown(ctx context.Context, dsn string) error

MigrateDown rolls back exactly one migration. Intended for local development only: invariant 8 calls for forward-only, additive migrations in operation.

func MigrationStatus

func MigrationStatus(ctx context.Context, dsn string) error

MigrationStatus writes the migration state to stdout.

func RequireTestDatabase

func RequireTestDatabase(dsn string) error

RequireTestDatabase refuses a DSN that does not name a test database.

The same rule as TruncateAll, applied before anything is opened, because the test harness migrates before it truncates — so a wrong DSN reached a live database with a schema change even though the truncate that followed was refused. A migration is additive by invariant 8 and the blast radius is small, but small is not none, and the point of issue #163 is to stop guessing about that.

Parsed with pgconn rather than net/url: a DSN may be a URL or the keyword/value form, and both reach the same driver.

func TruncateAll

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

TruncateAll empties every table. Intended exclusively for integration tests.

It used to say that callers reach it only behind a separately configured test DSN, and that this is what makes it safe. That was wrong in the one way that mattered: `task test:integration` configured that DSN to the database the office plays on, because compose.office.yaml is an overlay on the same `db` service — same volume, same port, one database. The safety argument and its defeat were eleven lines apart in the same repository (issue #163).

So the refusal lives here, where every caller passes, and it asks the server rather than reading the DSN. A connection string can be assembled in more ways than a check can anticipate; `current_database()` is the name of the thing that is about to be emptied, whoever built the string and however the environment was set.

Types

type Store

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

Store is the Postgres implementation of repository.Store.

func Open

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

Open builds a connection pool. The DSN comes exclusively from the environment (invariant 2); this package knows no default hosts.

func (*Store) Checkins added in v0.17.0

func (s *Store) Checkins() repository.CheckinRepository

Checkins returns the check-in repository.

func (*Store) Close

func (s *Store) Close()

Close releases the connection pool.

func (*Store) Credentials

func (s *Store) Credentials() repository.CredentialRepository

Credentials returns the credential repository.

func (*Store) FobWindow added in v0.17.0

func (s *Store) FobWindow() repository.FobWindowRepository

FobWindow returns the repository of the fob link window.

func (*Store) Identities

func (s *Store) Identities() repository.IdentityRepository

Identities returns the identity repository.

func (*Store) InTx

func (s *Store) InTx(ctx context.Context, fn func(repository.Store) error) error

InTx runs fn inside a transaction. If this Store is already bound to a transaction, fn continues in that same transaction.

func (*Store) KioskGrants

func (s *Store) KioskGrants() repository.KioskGrantRepository

KioskGrants returns the kiosk grant repository.

func (*Store) Matches

func (s *Store) Matches() repository.MatchRepository

Matches returns the match repository.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks that the database is reachable. Its consumer is /readyz.

func (*Store) Players

func (s *Store) Players() repository.PlayerRepository

Players returns the player repository.

func (*Store) TTRHistory

func (s *Store) TTRHistory() repository.TTRHistoryRepository

TTRHistory returns the rating history repository.

func (*Store) Tournaments

func (s *Store) Tournaments() repository.TournamentRepository

Tournaments returns the tournament repository.

Jump to

Keyboard shortcuts

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