Skip to content

Add PostgreSQL implementations for EventStore, APIKeyStore, IdempotencyStore, and DLQStore#216

Merged
intel352 merged 7 commits intomainfrom
copilot/add-postgresql-support-for-stores
Mar 1, 2026
Merged

Add PostgreSQL implementations for EventStore, APIKeyStore, IdempotencyStore, and DLQStore#216
intel352 merged 7 commits intomainfrom
copilot/add-postgresql-support-for-stores

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

  • Create store/pg_event_store.go - PostgreSQL EventStore using pgxpool
  • Create store/pg_api_keys.go - PostgreSQL APIKeyStore using pgxpool
  • Create store/pg_idempotency.go - PostgreSQL IdempotencyStore using pgxpool
  • Create store/pg_dlq.go - PostgreSQL DLQStore using pgxpool
  • Fix buildPGDLQQuery: remove dead idx++ after ErrorType
  • Fix PGEventStore.Append concurrency: use pg_advisory_xact_lock keyed on execution UUID to serialize per-execution appends
  • Add store/pg_stores_test.go: integration tests for all four PG stores, gated by PG_URL
  • Fix idempotency test cleanup: replace prefix-based DELETE WHERE key LIKE $1 with DELETE FROM idempotency_keys so fixed keys used by runIdempotencyTests ("order-123-step-validate", "expired-key", "dup-key", etc.) are properly cleaned up between runs
  • All tests pass, linter clean
Original prompt

This section details on the original issue you should resolve

<issue_title>Add PostgreSQL support for SQLite-only stores (EventStore, APIKeyStore, IdempotencyStore, DLQStore)</issue_title>
<issue_description>## Problem

Four core subsystems in store/ package only have SQLite implementations (plus InMemory for testing). This forces deployments to include SQLite even when PostgreSQL is the primary database.

Store File Interface
Event Store store/event_store.go EventStore
API Key Store store/api_keys.go APIKeyStore
Idempotency Store store/idempotency.go IdempotencyStore
Dead Letter Queue store/dlq.go DLQStore

All four use database/sql with modernc.org/sqlite driver and SQLite-specific DDL. The database.workflow module already supports both PostgreSQL (pgx) and SQLite, but these operational stores don't.

Proposed Solution

Follow the pattern already established in platform/state/ which has both sqlite_store.go and postgres_store.go:

  1. Create store/pg_event_store.go, store/pg_api_keys.go, store/pg_idempotency.go, store/pg_dlq.go
  2. Use PostgreSQL-compatible SQL (parameter placeholders $1, TIMESTAMPTZ, JSONB, UUID)
  3. Accept a *sql.DB or *pgxpool.Pool connection
  4. Add a factory function that selects the right implementation based on driver/config
  5. Use build tags or runtime detection to choose implementation

Key SQL Differences to Handle:

  • Parameter placeholders: ? (SQLite) → $1, $2, ... (PostgreSQL)
  • DDL: INTEGER PRIMARY KEY AUTOINCREMENTBIGSERIAL PRIMARY KEY
  • JSON columns: TEXTJSONB
  • Timestamps: TEXTTIMESTAMPTZ
  • UUIDs: TEXTUUID

Context

BuyMyWishlist and other PostgreSQL-first deployments shouldn't need SQLite as a dependency. The database.workflow module (module/database.go) already supports pgx driver — these stores should leverage it.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits March 1, 2026 08:54
…cyStore, and DLQStore

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
…cyStore, and DLQStore

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Copilot AI changed the title [WIP] Add PostgreSQL support for SQLite-only stores Add PostgreSQL implementations for EventStore, APIKeyStore, IdempotencyStore, and DLQStore Mar 1, 2026
@intel352 intel352 marked this pull request as ready for review March 1, 2026 09:36
Copilot AI review requested due to automatic review settings March 1, 2026 09:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds PostgreSQL-backed implementations for four core store/ subsystems (EventStore, APIKeyStore, IdempotencyStore, DLQStore) so PostgreSQL-first deployments aren’t forced to depend on SQLite for these operational stores.

Changes:

  • Introduces PGEventStore, PGAPIKeyStore, PGIdempotencyStore, and PGDLQStore using *pgxpool.Pool and PostgreSQL-native types (UUID, JSONB, TIMESTAMPTZ).
  • Creates required tables/indexes on construction via CREATE TABLE IF NOT EXISTS.
  • Updates go.mod to make github.com/xdg-go/scram a direct dependency.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
store/pg_event_store.go New Postgres event store implementation (append-only execution event log).
store/pg_api_keys.go New Postgres API key store implementation (CRUD + validation).
store/pg_idempotency.go New Postgres idempotency key store implementation (check/store/cleanup).
store/pg_dlq.go New Postgres DLQ store implementation (entry lifecycle + filtering).
go.mod Promotes xdg-go/scram to a direct dependency.

@intel352
Copy link
Contributor

intel352 commented Mar 1, 2026

@copilot apply changes based on the comments in this thread

…ntegration tests

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
@intel352
Copy link
Contributor

intel352 commented Mar 1, 2026

@copilot address this issue. #216 (comment)

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 1, 2026

@copilot address this issue. #216 (comment)

Fixed in 7eabfa3 — removed the dead idx++ (and its nolint comment) from the ErrorType block in buildPGDLQQuery. The placeholder numbering is unchanged; idx simply isn't needed after the last condition.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@intel352
Copy link
Contributor

intel352 commented Mar 1, 2026

@copilot apply changes based on the comments in this thread

…hed ones

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 1, 2026

@copilot apply changes based on the comments in this thread

Applied in 359e6fb — the idempotency subtest cleanup now uses DELETE FROM idempotency_keys instead of a prefix filter, ensuring all rows created by runIdempotencyTests (including hardcoded keys) are removed after each run.

@intel352 intel352 merged commit ae160f5 into main Mar 1, 2026
14 checks passed
@intel352 intel352 deleted the copilot/add-postgresql-support-for-stores branch March 1, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PostgreSQL support for SQLite-only stores (EventStore, APIKeyStore, IdempotencyStore, DLQStore)

3 participants