postgres

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package postgres provides a Postgres implementation of github.com/justinush/maestro/pkg/run.Store.

Workflow run state is stored in the workflow_runs table (JSONB column state). Canonical DDL lives in schema.sql (SchemaDDL returns the same bytes).

The table and column names are intended to remain stable across v0.x releases for this adapter.

Usage

pool, err := pgxpool.New(ctx, databaseURL)
if err != nil { ... }
store := postgres.NewStore(pool)

Store implements run.Store: Create, Get, Save with optimistic locking via revision. Store is safe for concurrent use when backed by a shared *pgxpool.Pool.

Schema management

Store expects workflow_runs to exist. Two supported approaches:

  • ApplySchema - optional helper for examples, tests, and quick local setup (idempotent).
  • Your migration tool - copy schema.sql or use SchemaDDL in goose / golang-migrate / Atlas / etc.

Scope

This package persists workflow runs only. Application-owned tables (users, applicants, etc.) remain the embedder's responsibility and are not coordinated in a single transaction with run.Store operations in v0.1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySchema

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

ApplySchema creates the workflow_runs table and indexes (idempotent).

Optional convenience for examples, local development, and integration tests. Production applications may prefer SchemaDDL with their own migration pipeline instead.

Store requires the schema to exist before use; how you apply it is up to the embedder.

func SchemaDDL

func SchemaDDL() string

SchemaDDL returns the canonical workflow_runs DDL (same as schema.sql).

Use this when applying the schema with your own migration tool (goose, golang-migrate, Atlas, etc.). Table and column names are intended to remain stable across v0.x releases.

Types

type Store

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

Store implements run.Store with Postgres (state as JSONB).

func NewStore

func NewStore(pool *pgxpool.Pool) *Store

NewStore returns a Store backed by pool.

The caller owns pool lifecycle. workflow_runs must exist before use (see ApplySchema or SchemaDDL).

func (*Store) Create

func (s *Store) Create(ctx context.Context, rec *run.RunRecord) error

Create inserts a new run. rec.RunID must be set; stored revision becomes 1.

func (*Store) Get

func (s *Store) Get(ctx context.Context, runID string) (*run.RunRecord, error)

Get returns a deep copy of the run or run.ErrNotFound.

func (*Store) Save

func (s *Store) Save(ctx context.Context, rec *run.RunRecord) error

Save updates the run when rec.Revision matches the stored value (then bumps revision).

Jump to

Keyboard shortcuts

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