Documentation
¶
Overview ¶
Package postgres is the ready-made Postgres implementation of directory.Stores: the tables, the queries, and the embedded migrations a product runs with Migrate under a version table of the module's own.
The JSONB documents it writes keep a fixed shape (see jsonb.go) so a product that already holds these tables reads and writes the same rows. Out of scope: connection pooling and transactions across stores, which are the caller's (pass a pgx.Tx to New to share one), and any table the directory does not own.
Index ¶
- Constants
- func Migrate(dsn string) error
- func MigrateDown(dsn string, version uint) error
- func MigrationFiles() fs.FS
- func New(db DB) directory.Stores
- type DB
- type SCIMTokens
- func (s *SCIMTokens) ClientByTokenHash(ctx context.Context, hash string) (*scim.Client, error)
- func (s *SCIMTokens) CreateClient(ctx context.Context, c *scim.Client) error
- func (s *SCIMTokens) ListClients(ctx context.Context) ([]*scim.Client, error)
- func (s *SCIMTokens) MarkUsed(ctx context.Context, name string, t time.Time) error
- func (s *SCIMTokens) RevokeClient(ctx context.Context, name string) error
- func (s *SCIMTokens) RotateClient(ctx context.Context, c *scim.Client) error
Constants ¶
const MigrationsTable = "auth_schema_migrations"
MigrationsTable is where the module records its schema version. It is its own table so the module's numbering never collides with the product's migrations on a shared database.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
Migrate runs the module's pending up-migrations against dsn, a postgres:// or postgresql:// URL. Running it when nothing is pending does nothing. A lock_timeout parameter in dsn bounds how long a migration waits for a table lock; one that gives up applied nothing and is left clean, so running Migrate again retries it. A clean schema at a version newer than this binary embeds is left alone, so an older binary still boots during a rolling upgrade or a rollback; that relies on the module's migrations staying backward-compatible.
func MigrateDown ¶
MigrateDown runs the module's down-migrations until the schema is at version; a schema at or below it, or never migrated, is left alone. A product whose own down-migrations drop tables that the module's later migrations change calls it first, so the next Migrate applies them again.
func MigrationFiles ¶
MigrationFiles returns the embedded migration files, for a product that fingerprints its schema, such as to key a cached test database.
Types ¶
type DB ¶
type DB interface {
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
Begin(ctx context.Context) (pgx.Tx, error)
}
DB is what the stores run statements on: a *pgxpool.Pool, a *pgx.Conn or a pgx.Tx. Begin on a transaction opens a savepoint, so a store whose write spans tables works unchanged inside the caller's transaction.
type SCIMTokens ¶
type SCIMTokens struct {
// contains filtered or unexported fields
}
SCIMTokens is the scim.TokenStore over the scim_clients table.
func NewSCIMTokens ¶
func NewSCIMTokens(db DB) *SCIMTokens
NewSCIMTokens returns the SCIM client store over db.
func (*SCIMTokens) ClientByTokenHash ¶
func (*SCIMTokens) CreateClient ¶
func (*SCIMTokens) ListClients ¶
func (*SCIMTokens) RevokeClient ¶
func (s *SCIMTokens) RevokeClient(ctx context.Context, name string) error