Help us shape the future of Go! Take the 2026 Go Developer Survey

database

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidApplicationName       = errors.New("invalid application name")
	ErrApplicationOwnershipConflict = errors.New("application is owned by another tenant")
)
View Source
var (
	ErrSchemaNotReady      = errors.New("database schema is not ready")
	ErrUnexpectedMigration = errors.New("database has unexpected migration")
)
View Source
var ErrInvalidPrincipal = errors.New("invalid principal")
View Source
var ErrInvalidTenantID = errors.New("invalid tenant id")
View Source
var ErrMissingDSN = errors.New("database DSN is required")
View Source
var ErrNoAppliedMigration = errors.New("no applied migration to roll back")

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) error

Migrate applies all embedded forward migrations exactly once in lexical order. Each migration runs in its own transaction. The migration table is authoritative.

func Open

func Open(ctx context.Context, cfg Config) (*pgxpool.Pool, error)

Open creates and verifies a PostgreSQL pool. It returns only after a successful ping.

func Ping

func Ping(ctx context.Context, pool *pgxpool.Pool) error

Ping verifies that PostgreSQL is reachable within the supplied context.

func RollbackLast

func RollbackLast(ctx context.Context, pool *pgxpool.Pool) error

RollbackLast reverses exactly the most recently applied BaseHarbor migration. A rollback file is mandatory; rollback never guesses or destroys earlier schema.

func VerifySchemaReady

func VerifySchemaReady(ctx context.Context, pool *pgxpool.Pool) error

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 Config

type Config struct {
	DSN            string
	ConnectTimeout time.Duration
	MaxConns       int32
	MinConns       int32
}

Config defines the PostgreSQL connection used by BaseHarbor.

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

func (*IdentityTenantResolver) ResolveTenant

func (r *IdentityTenantResolver) ResolveTenant(ctx context.Context, principal *identity.Principal) (*tenancy.Context, error)

Jump to

Keyboard shortcuts

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