postgres

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoundaryNames added in v0.8.0

func BoundaryNames(mappings map[string]config.BoundaryToPostgresSchemaMapping) []string

func LegacyBoundaryDefinitions added in v0.8.0

func LegacyBoundaryDefinitions(
	mappings map[string]config.BoundaryToPostgresSchemaMapping,
) []boundarymodel.Definition

LegacyBoundaryDefinitions translates existing PostgreSQL schema mappings into import commands. ORISUN_PG_SCHEMAS identifies the physical boundaries that must be represented in the event-backed catalog.

func RunDbScripts

func RunDbScripts(db *sql.DB, boundary string, schema string, isAdminSchema bool, ctx context.Context) error

RunDbScripts initializes database tables for a specific boundary. It validates the boundary name, creates the schema if needed, and calls the PostgreSQL initialization functions to create boundary-prefixed tables.

func RunDbScriptsWithDialect

func RunDbScriptsWithDialect(db *sql.DB, boundary string, schema string, isAdminSchema bool, dialect string, ctx context.Context) error

Types

type BoundaryRegistry added in v0.8.0

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

BoundaryRegistry is the shared, concurrency-safe source for every PostgreSQL component that resolves boundary-specific SQL.

func NewBoundaryRegistry added in v0.8.0

func NewBoundaryRegistry(mappings map[string]config.BoundaryToPostgresSchemaMapping) *BoundaryRegistry

func (*BoundaryRegistry) Mappings added in v0.8.0

func (*BoundaryRegistry) Register added in v0.8.0

func (r *BoundaryRegistry) Register(boundary, schema string) error

type DatabaseRuntime added in v0.8.0

type DatabaseRuntime struct {
	SaveEvents        eventstore.EventsSaver
	GetEvents         eventstore.EventsRetriever
	LockProvider      eventstore.LockProvider
	AdminDB           common.DB
	EventPublishing   eventstore.EventPublishingTracker
	Listener          *PGNotifyListener
	ProvisionBoundary func(context.Context, boundarymodel.Definition) error
	InstallBoundary   func(context.Context, boundarymodel.Definition) error
}

func InitializePostgresDatabaseRuntime added in v0.8.0

func InitializePostgresDatabaseRuntime(
	ctx context.Context,
	postgresDBConfig config.PostgresDBConfig,
	adminConfig config.AdminConfig,
	js jetstream.JetStream,
	logger logging.Logger,
) *DatabaseRuntime

type PGNotifyListener

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

func InitializePostgresDatabase

InitializePostgresDatabase preserves the original tuple API for callers that do not yet need dynamic boundary provisioning.

func NewPGNotifyListener

func NewPGNotifyListener(
	ctx context.Context,
	connStr string,
	boundarySchemaMapping map[string]config.BoundaryToPostgresSchemaMapping,
	logger logging.Logger,
) (*PGNotifyListener, error)

func (*PGNotifyListener) Close

func (l *PGNotifyListener) Close(ctx context.Context)

Close waits for the Start goroutine to stop (it closes the connection on exit). The caller must cancel the context passed to Start to trigger shutdown; Close itself returns once Start has finished or ctx is done.

func (*PGNotifyListener) EnsureBoundary added in v0.8.0

func (l *PGNotifyListener) EnsureBoundary(ctx context.Context, boundary string) error

EnsureBoundary installs LISTEN routing for a boundary on the listener-owned connection. It wakes WaitForNotification instead of using pgx.Conn concurrently.

func (*PGNotifyListener) Signal

func (l *PGNotifyListener) Signal(boundary string, catchupInterval time.Duration) orisun.EventSignal

func (*PGNotifyListener) Start

func (l *PGNotifyListener) Start(ctx context.Context)

Start owns l.conn exclusively for the lifetime of the goroutine: it is the only place the connection is read, swapped (via reconnect), or closed. No other goroutine may touch l.conn — pgx.Conn is not safe for concurrent use.

type PostgresAdminDB

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

func NewPostgresAdminDB

func NewPostgresAdminDB(db *sql.DB, logger logging.Logger, schema string, boundary string, boundarySchemaMappings map[string]config.BoundaryToPostgresSchemaMapping) *PostgresAdminDB

func NewPostgresAdminDBWithRegistry added in v0.8.0

func NewPostgresAdminDBWithRegistry(db *sql.DB, logger logging.Logger, schema string, boundary string, registry *BoundaryRegistry) *PostgresAdminDB

func (*PostgresAdminDB) CreateBoundaryIndex

func (db *PostgresAdminDB) CreateBoundaryIndex(
	ctx context.Context,
	boundary, name string,
	fields []eventstore.BoundaryIndexField,
	conditions []eventstore.BoundaryIndexCondition,
	combinator string,
) error

func (*PostgresAdminDB) DeleteUser

func (p *PostgresAdminDB) DeleteUser(id string) error

func (*PostgresAdminDB) DropBoundaryIndex

func (db *PostgresAdminDB) DropBoundaryIndex(
	ctx context.Context,
	boundary, name string,
) error

func (*PostgresAdminDB) GetEventsCount

func (s *PostgresAdminDB) GetEventsCount(boundary string) (int, error)

func (*PostgresAdminDB) GetProjectorLastPosition

func (s *PostgresAdminDB) GetProjectorLastPosition(projectorName string) (*eventstore.Position, error)

func (*PostgresAdminDB) GetUserById

func (s *PostgresAdminDB) GetUserById(id string) (eventstore.User, error)

func (*PostgresAdminDB) GetUserByUsername

func (s *PostgresAdminDB) GetUserByUsername(username string) (eventstore.User, error)

func (*PostgresAdminDB) GetUsersCount

func (s *PostgresAdminDB) GetUsersCount() (uint32, error)

func (*PostgresAdminDB) ListAdminUsers

func (s *PostgresAdminDB) ListAdminUsers() ([]*eventstore.User, error)

func (*PostgresAdminDB) SaveEventCount

func (s *PostgresAdminDB) SaveEventCount(event_count int, boundary string) error

func (*PostgresAdminDB) SaveUsersCount

func (s *PostgresAdminDB) SaveUsersCount(users_count uint32) error

func (*PostgresAdminDB) UpdateProjectorPosition

func (p *PostgresAdminDB) UpdateProjectorPosition(name string, position *eventstore.Position) error

func (*PostgresAdminDB) UpsertUser

func (s *PostgresAdminDB) UpsertUser(user eventstore.User) error

type PostgresBoundaryProvisioner added in v0.8.0

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

PostgresBoundaryProvisioner is the PostgreSQL adapter for the boundary_provisioning slice's ProvisionBoundary function port.

func NewPostgresBoundaryProvisioner added in v0.8.0

func NewPostgresBoundaryProvisioner(db *sql.DB, registry *BoundaryRegistry, dialect string) *PostgresBoundaryProvisioner

func (*PostgresBoundaryProvisioner) InstallBoundary added in v0.8.0

func (p *PostgresBoundaryProvisioner) InstallBoundary(_ context.Context, definition boundarymodel.Definition) error

InstallBoundary registers an already-provisioned boundary in one process's boundary-aware SQL adapters.

func (*PostgresBoundaryProvisioner) ProvisionBoundary added in v0.8.0

func (p *PostgresBoundaryProvisioner) ProvisionBoundary(ctx context.Context, definition boundarymodel.Definition) error

ProvisionBoundary validates and creates the physical PostgreSQL boundary. Cluster coordination ensures only one server process performs this work.

type PostgresEventPublishing

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

func NewPostgresEventPublishing

func NewPostgresEventPublishing(db *sql.DB, logger logging.Logger, boundarySchemaMappings map[string]config.BoundaryToPostgresSchemaMapping) *PostgresEventPublishing

func NewPostgresEventPublishingWithRegistry added in v0.8.0

func NewPostgresEventPublishingWithRegistry(db *sql.DB, logger logging.Logger, registry *BoundaryRegistry) *PostgresEventPublishing

func (*PostgresEventPublishing) GetLastPublishedEventPosition

func (s *PostgresEventPublishing) GetLastPublishedEventPosition(ctx context.Context, boundary string) (orisun.Position, error)

func (*PostgresEventPublishing) InsertLastPublishedEvent

func (s *PostgresEventPublishing) InsertLastPublishedEvent(ctx context.Context,
	boundaryOfInterest string, transactionId int64, globalId int64) error

func (*PostgresEventPublishing) Schema

func (s *PostgresEventPublishing) Schema(boundary string) (string, error)

type PostgresGetEvents

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

func NewPostgresGetEvents

func NewPostgresGetEvents(db *sql.DB, logger logging.Logger,
	boundarySchemaMappings map[string]config.BoundaryToPostgresSchemaMapping) *PostgresGetEvents

func NewPostgresGetEventsWithRegistry added in v0.8.0

func NewPostgresGetEventsWithRegistry(db *sql.DB, logger logging.Logger, registry *BoundaryRegistry) *PostgresGetEvents

func (*PostgresGetEvents) GetBatch

func (*PostgresGetEvents) GetLatestByCriteria

GetLatestByCriteria returns the latest event per criterion plus the max observed position. The per-criterion lookups run inside one SQL statement (get_latest_by_criteria_v1 builds a UNION ALL of LIMIT-1 subqueries), so the whole context comes from one snapshot — assembling it from independent queries would let an event commit in between with a position below the observed maximum, invisible to a scalar expected-position check.

func (*PostgresGetEvents) Schema

func (s *PostgresGetEvents) Schema(boundary string) (string, error)

type PostgresSaveEvents

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

func NewPostgresSaveEvents

func NewPostgresSaveEvents(
	ctx context.Context,
	db *sql.DB,
	logger logging.Logger,
	boundarySchemaMappings map[string]config.BoundaryToPostgresSchemaMapping) *PostgresSaveEvents

func NewPostgresSaveEventsWithRegistry added in v0.8.0

func NewPostgresSaveEventsWithRegistry(ctx context.Context, db *sql.DB, logger logging.Logger, registry *BoundaryRegistry) *PostgresSaveEvents

func (*PostgresSaveEvents) SavePrepared

func (s *PostgresSaveEvents) SavePrepared(
	ctx context.Context,
	events eventstore.PreparedEventBatch,
	boundary string,
	expectedPosition *eventstore.Position,
	streamConsistencyCondition *eventstore.Query) (transactionID string, globalID int64, err error)

func (*PostgresSaveEvents) Schema

func (s *PostgresSaveEvents) Schema(boundary string) (string, error)

Jump to

Keyboard shortcuts

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