Lyo.ChangeTracker.Postgres
1.0.1
dotnet add package Lyo.ChangeTracker.Postgres --version 1.0.1
NuGet\Install-Package Lyo.ChangeTracker.Postgres -Version 1.0.1
<PackageReference Include="Lyo.ChangeTracker.Postgres" Version="1.0.1" />
<PackageVersion Include="Lyo.ChangeTracker.Postgres" Version="1.0.1" />
<PackageReference Include="Lyo.ChangeTracker.Postgres" />
paket add Lyo.ChangeTracker.Postgres --version 1.0.1
#r "nuget: Lyo.ChangeTracker.Postgres, 1.0.1"
#:package Lyo.ChangeTracker.Postgres@1.0.1
#addin nuget:?package=Lyo.ChangeTracker.Postgres&version=1.0.1
#tool nuget:?package=Lyo.ChangeTracker.Postgres&version=1.0.1
Lyo.ChangeTracker.Postgres
PostgreSQL implementation of Lyo.ChangeTracker. Persists entity-scoped change history using Lyo.EntityReference.Models.EntityRef for both the target entity and the optional actor.
Features
PostgresChangeTrackerimplementing bothIChangeTrackerandLyo.Health.IHealth- EF Core migrations in the
change_trackerschema (PostgresChangeTrackerOptions.Schema) - Queryable history by entity, entity type, or change id (newest first)
DeleteForEntityAsyncto drop all history for a target entity- Optional automatic migrations on startup via
EnableAutoMigrations
Examples
Quick Start
services.AddPostgresChangeTracker(new PostgresChangeTrackerOptions {
ConnectionString = configuration.GetConnectionString("ChangeTracker")!,
EnableAutoMigrations = true
});
services.AddPostgresChangeTrackerFromConfiguration(configuration);
Migrations
export CHANGE_TRACKER_CONNECTION_STRING="Host=localhost;Database=change_tracker;Username=postgres;Password=postgres"
dotnet ef migrations add MigrationName --project Core/ChangeTracker/Lyo.ChangeTracker.Postgres
Registration
The package layers registration helpers so hosts can pick the level of integration they need:
| Extension | What it adds |
|---|---|
AddChangeTrackerDbContextFactory(options) / (Action<…>) |
Registers IDbContextFactory<ChangeTrackerDbContext> and the migrations helper (AddPostgresMigrations). |
AddChangeTrackerDbContextFactoryFromConfiguration(IConfiguration, …) |
Binds PostgresChangeTrackerOptions from "PostgresChangeTracker" (override the section via the optional configSectionName) and registers as above. |
AddChangeTrackerDbContext(connectionString) |
Builds options from a raw connection string, registers the factory, and exposes a scoped ChangeTrackerDbContext. |
AddChangeTrackerDbContext(Action<DbContextOptionsBuilder>) |
Uses a caller-provided DbContextOptionsBuilder (useful for tests or shared connection multiplexing). |
AddPostgresChangeTracker(options) / (Action<…>) |
Calls AddChangeTrackerDbContextFactory and registers IChangeTracker → PostgresChangeTracker as a singleton. |
AddPostgresChangeTrackerFromConfiguration(IConfiguration, …) |
Same as the options overload, binding from configuration. |
Health
PostgresChangeTracker implements Lyo.Health.IHealth with HealthCheckName = "change-tracker-postgres". The probe opens a ChangeTrackerDbContext and runs Database.CanConnectAsync, returning a HealthResult with the schema name in its data bag — so the tracker contributes to host health endpoints that resolve IEnumerable<IHealth>.
Schema
- All tables live in the
change_trackerschema (seePostgresChangeTrackerOptions.Schema). change_tracker.changes— subject (for_entity_*/SubjectEntityType), optional actor (from_entity_*/ActorEntityType), nullabletenant_id(uuid), JSONOldValues, JSONChangedProperties, optionalChangeType/Message, andTimestamp.
Tenancy
ChangeRecord carries an optional TenantId; null denotes a system / untenanted row. PostgresChangeTracker runs every record through TenancyResolver.Resolve using the
policy configured in PostgresChangeTrackerOptions.Tenancy (inheriting from EntityRefOptions.Mode when unset) before persisting:
SystemOnly— callerTenantIdis ignored; the row storesnull.SingleTenantDefault(default) — caller value, falling back toTenancy.DefaultTenantIdthenEntityRefOptions.DefaultTenantId.MultiTenantStrict— caller must supply a non-emptyTenantIdor persistence throws.
The ix_changes_tenant index supports per-tenant lookups. Use the
WhereTenant / WhereTenantOrSystem helpers from Lyo.EntityReference.Postgres to query the table.
{
"PostgresChangeTracker": {
"ConnectionString": "Host=localhost;Database=change_tracker;...",
"Tenancy": { "Mode": "SystemOnly" }
}
}
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.ChangeTracker— (direct, lyo)Lyo.EntityReference.Models— (direct, lyo)Lyo.EntityReference.Postgres— (direct, lyo)Lyo.Exceptions— (direct, lyo)Lyo.Health— (direct, lyo)Lyo.Postgres— (direct, lyo)Microsoft.Extensions.Configuration.Binder10.0.5— (direct, microsoft)Lyo.Common— (transitive, lyo)Microsoft.EntityFrameworkCore10.0.5— (transitive, microsoft)Microsoft.EntityFrameworkCore.Design10.0.5— (transitive, microsoft)Microsoft.EntityFrameworkCore.Relational10.0.5— (transitive, microsoft)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5— (transitive, microsoft)Microsoft.Extensions.Hosting.Abstractions10.0.5— (transitive, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5— (transitive, microsoft)Microsoft.Extensions.Options10.0.5— (transitive, microsoft)Microsoft.Extensions.Options.ConfigurationExtensions10.0.5— (transitive, microsoft)Npgsql.EntityFrameworkCore.PostgreSQL10.0.3— (transitive, third-party)System.Memory4.6.3— (transitive, microsoft, netstandard2.0)System.Text.Json10.0.5— (transitive, microsoft, netstandard2.0)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Lyo.ChangeTracker (>= 1.0.1)
- Lyo.EntityReference.Models (>= 1.0.1)
- Lyo.EntityReference.Postgres (>= 1.0.1)
- Lyo.Exceptions (>= 1.0.1)
- Lyo.Health (>= 1.0.1)
- Lyo.Postgres (>= 1.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.