Documentation
¶
Index ¶
- Variables
- func Migrate(ctx context.Context, pool *pgxpool.Pool) error
- func Open(ctx context.Context, cfg Config) (*pgxpool.Pool, error)
- func Ping(ctx context.Context, pool *pgxpool.Pool) error
- func RollbackLast(ctx context.Context, pool *pgxpool.Pool) error
- func VerifySchemaReady(ctx context.Context, pool *pgxpool.Pool) error
- func WithTenantTx(ctx context.Context, pool *pgxpool.Pool, tenantID string, ...) error
- type ApplicationOwnershipStore
- type Config
- type IdentityTenantResolver
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidApplicationName = errors.New("invalid application name") ErrApplicationOwnershipConflict = errors.New("application is owned by another tenant") )
var ( ErrSchemaNotReady = errors.New("database schema is not ready") ErrUnexpectedMigration = errors.New("database has unexpected migration") )
var ErrInvalidPrincipal = errors.New("invalid principal")
var ErrInvalidTenantID = errors.New("invalid tenant id")
var ErrMissingDSN = errors.New("database DSN is required")
var ErrNoAppliedMigration = errors.New("no applied migration to roll back")
Functions ¶
func Migrate ¶
Migrate applies all embedded forward migrations exactly once in lexical order. Each migration runs in its own transaction. The migration table is authoritative.
func RollbackLast ¶
RollbackLast reverses exactly the most recently applied BaseHarbor migration. A rollback file is mandatory; rollback never guesses or destroys earlier schema.
func VerifySchemaReady ¶
VerifySchemaReady verifies the authoritative migration state without mutating it. Runtime processes must not apply migrations implicitly during startup.
func WithTenantTx ¶
func WithTenantTx(ctx context.Context, pool *pgxpool.Pool, tenantID string, fn func(pgx.Tx) error) error
WithTenantTx runs fn inside a transaction whose PostgreSQL session context is scoped to exactly one tenant. SET LOCAL semantics ensure the tenant context is automatically discarded when the transaction ends.
Types ¶
type ApplicationOwnershipStore ¶
type ApplicationOwnershipStore struct {
// contains filtered or unexported fields
}
ApplicationOwnershipStore is the authoritative persistence boundary for application-to-tenant ownership.
func NewApplicationOwnershipStore ¶
func NewApplicationOwnershipStore(pool *pgxpool.Pool) *ApplicationOwnershipStore
func (*ApplicationOwnershipStore) Claim ¶
func (s *ApplicationOwnershipStore) Claim(ctx context.Context, tenantID, applicationName string) error
func (*ApplicationOwnershipStore) OwnedByTenant ¶
func (s *ApplicationOwnershipStore) OwnedByTenant(ctx context.Context, tenantID, applicationName string) (bool, error)
OwnedByTenant implements the application-secret API ownership resolver. The lookup is tenant-scoped and therefore subject to PostgreSQL RLS.
type IdentityTenantResolver ¶
type IdentityTenantResolver struct {
// contains filtered or unexported fields
}
IdentityTenantResolver resolves memberships for one verified external identity before a tenant scope exists. Access remains constrained by the identity-resolution RLS policy; no BYPASSRLS or superuser privilege is used.
func NewIdentityTenantResolver ¶
func NewIdentityTenantResolver(pool *pgxpool.Pool) *IdentityTenantResolver