postgres

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package postgres provides durable atomic capability consumption through database/sql and PostgreSQL row locks. The caller supplies the SQL driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateLegacyConsumption

func MigrateLegacyConsumption(ctx context.Context, tx *sql.Tx, legacyIssuer string) error

MigrateLegacyConsumption upgrades migration 001 to the issuer-scoped schema version 2, preserving every use count, maximum and expiry. legacyIssuer must be the owner-proven single issuer of all existing rows, never a token claim. The caller must fence and drain all old writers first and supply an open transaction. This function locks the table but does not commit or roll back; on failure the caller must roll back. Commit before activating new writers. An already upgraded schema is not migrated again. Unknown legacy ownership requires retiring old grants beyond expiry plus verification skew instead.

Types

type ConsumptionStore

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

ConsumptionStore owns durable PostgreSQL transactions for replay state.

func NewConsumptionStore

func NewConsumptionStore(db *sql.DB) (*ConsumptionStore, error)

NewConsumptionStore binds store to db. The schema in migrations must be installed and MigrateLegacyConsumption committed before use. db remains caller-owned and is never closed here.

func (*ConsumptionStore) Cleanup

func (store *ConsumptionStore) Cleanup(ctx context.Context, cutoff time.Time) (int64, error)

Cleanup deletes state whose expiry is at or before cutoff.

func (*ConsumptionStore) Consume

Consume serializes one capability row, then commits an increment only when the signed identity and use bound match. Commit errors have unknown outcome.

Jump to

Keyboard shortcuts

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