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
- func Migrate(ctx context.Context, dsn string) error
- func MigrateDown(ctx context.Context, dsn string) error
- func MigrationStatus(ctx context.Context, dsn string) error
- func RequireTestDatabase(dsn string) error
- func TruncateAll(ctx context.Context, s *Store) error
- type Store
- func (s *Store) Checkins() repository.CheckinRepository
- func (s *Store) Close()
- func (s *Store) Credentials() repository.CredentialRepository
- func (s *Store) FobWindow() repository.FobWindowRepository
- func (s *Store) Identities() repository.IdentityRepository
- func (s *Store) InTx(ctx context.Context, fn func(repository.Store) error) error
- func (s *Store) KioskGrants() repository.KioskGrantRepository
- func (s *Store) Matches() repository.MatchRepository
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) Players() repository.PlayerRepository
- func (s *Store) TTRHistory() repository.TTRHistoryRepository
- func (s *Store) Tournaments() repository.TournamentRepository
Constants ¶
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 ¶
Migrate applies all pending migrations. The migrations are embedded in the binary, so the image brings them along itself.
func MigrateDown ¶
MigrateDown rolls back exactly one migration. Intended for local development only: invariant 8 calls for forward-only, additive migrations in operation.
func MigrationStatus ¶
MigrationStatus writes the migration state to stdout.
func RequireTestDatabase ¶
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 ¶
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 ¶
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) 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 ¶
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) 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.