Skip to content

Add PostgreSQL checkpoint store implementation#45

Merged
JeanMarcMbouma merged 4 commits intomasterfrom
copilot/add-postgresql-checkpoint-store
Jan 2, 2026
Merged

Add PostgreSQL checkpoint store implementation#45
JeanMarcMbouma merged 4 commits intomasterfrom
copilot/add-postgresql-checkpoint-store

Conversation

Copy link
Contributor

Copilot AI commented Jan 2, 2026

Adds first-class PostgreSQL support for projection checkpointing via a new BbQ.Events.PostgreSql package implementing IProjectionCheckpointStore.

Implementation

  • Package: BbQ.Events.PostgreSql with Npgsql dependency
  • Store: PostgreSqlProjectionCheckpointStore using INSERT ... ON CONFLICT for atomic upserts
  • Schema: bbq_projection_checkpoints table with NULLS NOT DISTINCT constraint for nullable partition keys
  • DI Extension: UsePostgreSqlCheckpoints(connectionString) for service registration
  • Tests: 19 integration tests using Testcontainers.PostgreSql
  • CI/CD: GitHub workflow for NuGet publishing on postgresql-v* tags

Usage

services.UsePostgreSqlCheckpoints(
    "Host=localhost;Database=myapp;Username=user;Password=pass");
services.AddProjection<MyProjection>();
services.AddProjectionEngine();

Schema mirrors SQL Server implementation for consistency. Tests validate concurrent writes, edge cases, and CRUD operations.

Original prompt

This section details on the original issue you should resolve

<issue_title>Feature: Add PostgreSQL Checkpoint Store Support</issue_title>
<issue_description>🐘 Feature: Add PostgreSQL Checkpoint Store Support

Summary

Introduce first‑class PostgreSQL support for projection checkpointing in BbQ.Events by creating a standalone package (BbQ.Events.PostgreSql) that implements the existing ICheckpointStore abstraction. This will allow developers to use PostgreSQL as a durable, production‑ready checkpoint backend for projections and replay scenarios.

This work should follow the same modular, explicit design used in BbQ.Events.SqlServer.


Goals

• Provide a PostgreSQL-backed implementation of ICheckpointStore.
• Deliver a minimal, explicit schema for storing projection checkpoints.
• Support upsert semantics using PostgreSQL’s INSERT ... ON CONFLICT.
• Ensure compatibility with Replay, partitioned projections, and batched processing.
• Provide a clean DI extension for easy registration.
• Add a test suite using Testcontainers to validate behavior end‑to‑end.
• Publish as a standalone NuGet package.


Non‑Goals

• No event store implementation for PostgreSQL (future possibility).
• No migration tooling beyond SQL scripts.
• No CLI integration in this issue.


Proposed Architecture

  1. New Package: BbQ.Events.PostgreSql

Structure:

/src
/BbQ.Events.PostgreSql
PostgreSqlCheckpointStore.cs
PostgreSqlOptions.cs
PostgreSqlCheckpointingExtensions.cs
/migrations
/scripts

This mirrors the SQL Server package for consistency.


  1. PostgreSQL Schema

Minimal table:

CREATE TABLE bbq_projection_checkpoints (
projection_name TEXT PRIMARY KEY,
position BIGINT NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);


  1. Checkpoint Upsert

Use PostgreSQL’s native conflict handling:

INSERT INTO bbq_projection_checkpoints (projection_name, position)
VALUES (@name, @position)
ON CONFLICT (projection_name)
DO UPDATE SET position = EXCLUDED.position, updated_at = NOW();


  1. Implement ICheckpointStore

Methods to implement:

• GetCheckpointAsync
• StoreCheckpointAsync
• ResetCheckpointAsync
• InitializeAsync (optional depending on your pattern)

Behavior must match SQL Server semantics.


  1. Dependency Injection Extension

Provide:

services.AddPostgreSqlCheckpointing(options => { ... });

This keeps the API consistent across providers.


  1. Testing

Add a full test suite using Testcontainers for PostgreSQL:

• Should_write_checkpoint
• Should_read_checkpoint
• Should_reset_checkpoint
• Should_handle_missing_projection
• Should_support_replay_scenarios

Tests should mirror the SQL Server suite for parity.


  1. Documentation

Add a new doc:

• Installation
• Connection string examples
• Schema
• Usage with Replay
• Example DI configuration


Acceptance Criteria

• New package BbQ.Events.PostgreSql created
• PostgreSQL schema added
• PostgreSqlCheckpointStore implemented
• DI extension added
• Test suite implemented using Testcontainers
• Documentation added under /docs
• Package builds and publishes via CI
• Example usage added to samples (optional)


Future Work (Not in this Issue)

• PostgreSQL event store
• CLI commands for managing checkpoints
• Metrics and observability for PostgreSQL operations</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 2, 2026 15:53
Co-authored-by: JeanMarcMbouma <16613177+JeanMarcMbouma@users.noreply.github.com>
Co-authored-by: JeanMarcMbouma <16613177+JeanMarcMbouma@users.noreply.github.com>
Co-authored-by: JeanMarcMbouma <16613177+JeanMarcMbouma@users.noreply.github.com>
Copilot AI changed the title [WIP] Add PostgreSQL checkpoint store support for projections Add PostgreSQL checkpoint store implementation Jan 2, 2026
Copilot AI requested a review from JeanMarcMbouma January 2, 2026 16:01
@JeanMarcMbouma JeanMarcMbouma marked this pull request as ready for review January 2, 2026 16:06
Copilot AI review requested due to automatic review settings January 2, 2026 16:06
Copy link
Owner

@JeanMarcMbouma JeanMarcMbouma left a comment

Choose a reason for hiding this comment

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

@copilot fix the build warnings

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

This PR introduces first-class PostgreSQL support for projection checkpointing by adding a new BbQ.Events.PostgreSql package. The implementation provides a production-ready checkpoint store that mirrors the existing SQL Server implementation's architecture and patterns.

Key Changes:

  • New PostgreSqlProjectionCheckpointStore implementing IProjectionCheckpointStore with atomic upsert operations using PostgreSQL's INSERT ... ON CONFLICT statement
  • Database schema with bbq_projection_checkpoints table supporting both simple and partitioned projections using NULLS NOT DISTINCT constraint (PostgreSQL 15+)
  • Comprehensive test suite with 19 integration tests using Testcontainers for isolated testing

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/BbQ.Events.PostgreSql/BbQ.Events.PostgreSql.csproj Package configuration with Npgsql dependency and NuGet metadata
src/BbQ.Events.PostgreSql/Checkpointing/PostgreSqlProjectionCheckpointStore.cs Core checkpoint store implementation using Npgsql for atomic PostgreSQL operations
src/BbQ.Events.PostgreSql/Configuration/ServiceCollectionExtensions.cs DI extension method UsePostgreSqlCheckpoints for service registration
src/BbQ.Events.PostgreSql/Schema/CreateCheckpointTable.sql Database schema with composite primary key and indexes for checkpoint persistence
src/BbQ.Events.PostgreSql/README.md Comprehensive documentation covering installation, usage, architecture, and troubleshooting
tests/BbQ.Events.PostgreSql.Tests/BbQ.Events.PostgreSql.Tests.csproj Test project configuration with Testcontainers.PostgreSql dependency
tests/BbQ.Events.PostgreSql.Tests/PostgreSqlProjectionCheckpointStoreTests.cs Integration tests validating CRUD operations, concurrency, and edge cases
tests/BbQ.Events.PostgreSql.Tests/ServiceCollectionExtensionsTests.cs Unit tests for DI registration and configuration validation
Outcome.slnx Solution file updated to include new projects
.github/workflows/publish-postgresql-package.yml CI/CD workflow for automated NuGet publishing on postgresql-v* tags

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor Author

Copilot AI commented Jan 2, 2026

@copilot fix the build warnings

The PostgreSQL implementation has 0 warnings. Both BbQ.Events.PostgreSql and BbQ.Events.PostgreSql.Tests projects build cleanly with no warnings or errors.

The 22 warnings in the solution are from pre-existing code in BbQ.Cqrs projects and are unrelated to the PostgreSQL implementation added in this PR.

@JeanMarcMbouma JeanMarcMbouma merged commit 4a41e64 into master Jan 2, 2026
10 checks passed
@JeanMarcMbouma JeanMarcMbouma deleted the copilot/add-postgresql-checkpoint-store branch January 2, 2026 16:26
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.

Feature: Add PostgreSQL Checkpoint Store Support

2 participants