Module github.com/bide-ai/bide/govern/postgreslog
Go module github.com/bide-ai/bide/govern/postgreslog; all modules.
govern/postgreslog
github.com/bide-ai/bide/govern/postgreslog · pkg.go.dev · Stability: experimental
Package postgreslog is a Postgres-backed govern.EventLog for HIGH-AVAILABILITY governed state: multiple processes read the same governed event stream and replay it to the same convergent state.
Variables
var ErrSchemaMissing: ErrSchemaMissing is wrapped by the error Open returns when the log's schema (the pinned schema, governed_events with its append_id index, or the next_seq function) does not exist and the log was opened WithoutMigration.var ErrSchemaVersion: ErrSchemaVersion is wrapped by the error returned when the log's recorded schema version is not the one this version of the package uses: a newer one needs a newer program, and there is no migration from another one.
Functions
func Migrate(ctx context.Context, dsn string, opts ...Option) error: Migrate opens the log at dsn as the role in the DSN, which needs the privileges of the schema's owner, creates or migrates governed_events and the next_seq function as Open does, checks them, and closes the pool.
type Log
go
type Log struct {
// contains filtered or unexported fields
}Log is a Postgres-backed append-only event log per entity.
Constructors and functions
func Open(ctx context.Context, dsn string, opts ...Option) (*Log, error): Open connects to Postgres via a pgx DSN (e.g. "postgres://user:pass@host:5432/db") and ensures the schema exists, or with WithoutMigration only verifies it.
Methods
func (l *Log) Append(ctx context.Context, entity, id, event string) (int64, error): Append durably records an event for an entity under id and returns its position (its seq).func (l *Log) Close() error: Close releases the underlying database connection pool.func (l *Log) Events(ctx context.Context, entity string, from int64) ([]string, error): Events returns an entity's events at positions from onward, in log order.
type Option
go
type Option interface {
// contains filtered or unexported methods
}Option configures Open.
Constructors and functions
func WithSchema(name string) Option: WithSchema pins the schema governed_events and its next_seq function are in, instead of discovering it through the search path at every Open.func WithoutMigration() Option: WithoutMigration makes Open verify the schema instead of creating it: it runs no CREATE and no ALTER, so its role needs no CREATE on the schema.