Documentation
¶
Overview ¶
Package store is the metering engine's database seam: the pgx connection pool and the migrator that applies the embedded engine chain.
Opening a Store does not dial the database. The connection is established on the first query, so a subcommand that only parses its flags fails on the flags rather than on the database. The engine never runs DDL outside the migrate subcommands of its CLI: a schema change is an operator's decision.
The static queries in queries.sql are compiled by sqlc into the sqlcgen subpackage, which takes the pool as its DBTX. `make generate` rewrites that package, and it is committed so that a plain `go build` needs no generator.
The normative specification is roadmap/03-phase-3-metering-rating.md, WP 3.1.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
Migrate applies every pending migration of the embedded engine chain and returns the versions it applied, oldest first. An up-to-date database yields an empty slice and no error.
Only the engine CLI and the integration tests call this. No other subcommand runs DDL as a side effect: a schema change is an operator's decision, not something a scheduled run brings along.
func MigrateDownTo ¶
MigrateDownTo rolls the chain back to version, applying the down migration of everything above it, and returns the versions it rolled back. Passing 0 leaves an empty schema.
It is the counterpart of Migrate: the chain ships down migrations, and a rollback nobody can run is a rollback that does not exist.
Types ¶
type MigrationState ¶
type MigrationState = dbmigrate.MigrationState
MigrationState is one migration of the chain and whether the database carries it. It is what answers "which schema is this database on" before code that assumes a newer one is run against it.
func MigrationStatus ¶
func MigrationStatus(ctx context.Context, dbURL string) ([]MigrationState, error)
MigrationStatus reports every migration of the embedded chain against the database, oldest first.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store owns the connection pool the engine reads and writes through.
func New ¶
New parses dbURL and prepares the pool for it. Connections are established lazily, so a database that is down does not keep the process from starting.
func (*Store) CheckSchema ¶
CheckSchema refuses a database that carries less of the migration chain than this build was compiled against. It is what every subcommand runs before its first query, so that a deployment whose migrate step lagged behind the image fails on the cause rather than on whichever column the missing migration was going to add, halfway through a run.
A database without this chain's bookkeeping is a database this chain never ran against, which is version 0 and reported as such. The table carries the engine's own name, so a connection string that reaches another service's database — the reporting one, a copy-paste away in a deployment that carries both — reads 0 here rather than that chain's position, which is a number the comparison below has no meaning against. Every other failed read is reported as it came back: a read that did not answer is not a pass, and a gate that lets one through is a gate that disables itself on the deployment it exists for. The relation is schema-qualified for the reason migration 0001 pins the trigger function's search_path.