store

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Migrate(ctx context.Context, dbURL string) ([]int64, error)

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

func MigrateDownTo(ctx context.Context, dbURL string, version int64) ([]int64, error)

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

func New(ctx context.Context, dbURL string) (*Store, error)

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

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

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.

func (*Store) Close

func (s *Store) Close()

Close releases every connection the pool holds and waits for in-flight ones to be returned.

func (*Store) Pool

func (s *Store) Pool() *pgxpool.Pool

Pool returns the underlying pool, which is what the generated sqlc queries take as their DBTX.

Directories

Path Synopsis
Package storetest hands integration tests a plain PostgreSQL 16 container with the engine migration chain applied.
Package storetest hands integration tests a plain PostgreSQL 16 container with the engine migration chain applied.

Jump to

Keyboard shortcuts

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