postgres

package
v1.3.0 Latest Latest
Warning

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

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

README

PostgreSQL backend

PostgreSQL stores histories, pending events, timers and activity tasks for workers sharing one database. See backend operations for durability, retention and storage isolation.

Connections and migrations

NewPostgresBackend opens and owns a pgx-backed SQL connection and applies embedded migrations by default. Its convenience connection string uses sslmode=disable. For a remote database requiring TLS or other connection policy, configure a *sql.DB in the host application and pass it to NewPostgresBackendWithDB.

NewPostgresBackendWithDB leaves connection ownership with the caller and disables migrations by default. Enable them explicitly with WithApplyMigrations(true) when the application owns migration startup. Close does not close a caller-owned connection. WithPostgresOptions configures connections opened by the convenience constructor.

Constructors can panic when initialization or automatic migration fails. Keep credentials outside source and apply migrations before accepting work. Back up the database before schema upgrades.

Maintaining the backend

Embedded migrations live in db/migrations, with paired .up.sql and .down.sql files. Follow the existing sequence and preserve published migrations. Test schema changes against real PostgreSQL using the production constructor and migration path.

The common-go PostgreSQL wrapper opens owned connections and runs the embedded migrations. db/models mirrors the existing schema, and db/repositories contains generated typed accessors. Read-committed transactions keep row claims and checkpoints atomic; skip-locked selection lets replicas claim different work. See generation.

Run make test-postgres for backend contracts and make test-recovery for independent worker process recovery. Both use isolated PostgreSQL with -race; neither needs a production database. See testing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgresBackend

func NewPostgresBackend(host string, port int, user, password, database string, opts ...option) *postgresBackend

func NewPostgresBackendWithDB

func NewPostgresBackendWithDB(pool *sql.DB, opts ...option) *postgresBackend

NewPostgresBackendWithDB leaves connection configuration and ownership with the caller. Automatic migrations are disabled by default.

func WithApplyMigrations

func WithApplyMigrations(applyMigrations bool) option

WithApplyMigrations automatically applies database migrations on startup.

func WithBackendOptions

func WithBackendOptions(opts ...backend.BackendOption) option

WithBackendOptions allows to pass generic backend options.

func WithPostgresOptions

func WithPostgresOptions(f func(db *sql.DB)) option

Types

This section is empty.

Directories

Path Synopsis
db
Package db owns postgres connection setup and the backend's immutable migration history.
Package db owns postgres connection setup and the backend's immutable migration history.

Jump to

Keyboard shortcuts

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