Skip to content

feat: PostgreSQL ADO.NET implementation of IIdempotencyStore#391

Merged
samtrion merged 3 commits intomainfrom
copilot/add-postgresql-idoempotencystore
Apr 15, 2026
Merged

feat: PostgreSQL ADO.NET implementation of IIdempotencyStore#391
samtrion merged 3 commits intomainfrom
copilot/add-postgresql-idoempotencystore

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

Adds a PostgreSQL-native IIdempotencyKeyRepository backed by Npgsql ADO.NET, mirroring the existing SQL Server implementation without requiring EF Core.

DDL (Scripts/IdempotencyKey.sql)

  • Table IdempotencyKey with idempotency_key VARCHAR(500) PK and created_at TIMESTAMP WITH TIME ZONE
  • fn_exists_idempotency_key(key, valid_from?) — TTL-aware existence check
  • fn_insert_idempotency_key(key, created_at)INSERT … ON CONFLICT DO NOTHING
  • fn_delete_expired_idempotency_keys(valid_from) — cleanup helper

Implementation

  • PostgreSqlIdempotencyKeyRepository (internal sealed) — calls the above functions via NpgsqlCommand; catches PostgresException with SqlState == "23505" in StoreAsync as a safety net
  • PostgreSqlIdempotencyMediatorBuilderExtensions — three AddPostgreSqlIdempotencyStore overloads (connection string, factory, options action) registering IIdempotencyKeyRepository as Scoped

Usage

services.AddPulse(config => config
    .AddPostgreSqlIdempotencyStore(
        "Host=localhost;Database=MyDb;Username=postgres;******;",
        opts => opts.TimeToLive = TimeSpan.FromHours(24)
    )
);

Tests

  • Constructor validation tests for PostgreSqlIdempotencyKeyRepository
  • DI registration tests for all three extension overloads (service types, lifetimes, options wiring)
  • Integration tests (PostgreSqlAdoNetIdempotencyTests) running against a real PostgreSQL container via Testcontainers, covering: key absent, key present, different key, multiple keys, duplicate insert (same scope), cross-scope duplicate insert (exercises the 23505 catch path), TTL within range, and TTL expired scenarios

Copilot AI changed the title [WIP] Add IIdempotencyStore implementation for PostgreSQL ADO.NET feat: PostgreSQL ADO.NET implementation of IIdempotencyStore Apr 15, 2026
Copilot AI requested a review from samtrion April 15, 2026 13:41
@samtrion
Copy link
Copy Markdown
Contributor

@copilot Add also Integration tests

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 15, 2026

@copilot Add also Integration tests

Added in f9e0cdd:

  • PostgreSqlAdoNetIdempotencyInitializer — reads Scripts/IdempotencyKey.sql, substitutes :schema_name/:table_name placeholders (same approach as the outbox initializer), and wires up AddPostgreSqlIdempotencyStore
  • PostgreSqlAdoNetIdempotencyTests — inherits all 8 scenarios from IdempotencyTestsBase (key absent, key present, different key, multiple keys, duplicate insert, cross-scope duplicate, TTL within range, TTL expired) running against a real PostgreSQL container via Testcontainers

@samtrion samtrion marked this pull request as ready for review April 15, 2026 19:42
@samtrion samtrion requested a review from a team as a code owner April 15, 2026 19:42
@samtrion samtrion added state:ready for merge Indicates that a pull request has been reviewed and approved, and is ready to be merged into the mai type:feature Indicates a new feature or enhancement to be added. labels Apr 15, 2026
@samtrion samtrion merged commit ad1cce2 into main Apr 15, 2026
4 checks passed
@samtrion samtrion deleted the copilot/add-postgresql-idoempotencystore branch April 15, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:ready for merge Indicates that a pull request has been reviewed and approved, and is ready to be merged into the mai type:feature Indicates a new feature or enhancement to be added.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: IIdempotencyStore – PostgreSQL ADO.NET implementation

2 participants