Skip to content

Make Argus.Sync.EntityFramework provider-agnostic (support EF Core adapters beyond Postgres) #178

Description

@Mercurial

Summary

Argus.Sync.EntityFramework is named for EF Core (which is provider-agnostic) but is currently wired specifically to PostgreSQL. EF Core supports many providers — SQLite, SQL Server, MySQL/MariaDB, etc. — and the bulk of the backend is already provider-neutral, so opening it up is a contained change.

What is already provider-agnostic

CardanoDbContext, EfBlockUnitOfWork, and EfBlockUnitOfWorkFactory use only EF Core APIs (SaveChanges, transactions, the change-tracker) — no Npgsql types.

  • Caveat: EfBlockUnitOfWork sets Database.AutoSavepointsEnabled = false. That is a generic EF property, but the motivation was an Npgsql quirk (auto-savepoints tripping under repeated same-transaction SaveChanges). Worth confirming the value is correct/harmless on other providers.

What is Postgres-specific today

  1. RegistrationEfServiceCollectionExtensions.cs hardcodes options.UseNpgsql(...) (one line).
  2. Single-instance lockPostgresSingleInstanceLockWorker is entirely NpgsqlConnection + pg_advisory_lock / pg_advisory_unlock. This is the only genuinely DB-specific component.
  3. Package dependency — pulls Npgsql.EntityFrameworkCore.PostgreSQL.

Proposed approach

  • Pluggable provider: add a generic registration that takes the provider setup, e.g. AddCardanoEntityFrameworkIndexer<TContext>(config, Action<DbContextOptionsBuilder> configureProvider), and keep AddCardanoPostgresIndexer<T> as a thin convenience wrapper (configureProvider = o => o.UseNpgsql(...)) so current behavior is unchanged.
  • Pluggable lock: the single-instance lock already sits behind ISingleInstanceLock (core), with Postgres + Mongo implementations. For a new EF provider, either:
    • supply a native lock (SQL Server sp_getapplock, MySQL GET_LOCK, …), or
    • provide a generic EF lease-lock (a ReducerLocks row with atomic upsert + heartbeat, like the Mongo lease) as a provider-neutral default — less ideal than native advisory locks, but works on any provider.
  • Packaging decision: keep Argus.Sync.EntityFramework generic with Postgres as a supported provider, vs. split the Npgsql dependency into a separate Argus.Sync.EntityFramework.Postgres.

Scope note

The unit of work and DbContext are free; the real per-provider cost is the single-instance lock (plus verifying the savepoint setting). Ship Postgres as the reference implementation and document "bring your own EF provider."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions