Lyo.ChangeTracker.Postgres 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Lyo.ChangeTracker.Postgres --version 1.0.0
                    
NuGet\Install-Package Lyo.ChangeTracker.Postgres -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lyo.ChangeTracker.Postgres" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lyo.ChangeTracker.Postgres" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Lyo.ChangeTracker.Postgres" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lyo.ChangeTracker.Postgres --version 1.0.0
                    
#r "nuget: Lyo.ChangeTracker.Postgres, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lyo.ChangeTracker.Postgres@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lyo.ChangeTracker.Postgres&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Lyo.ChangeTracker.Postgres&version=1.0.0
                    
Install as a Cake Tool

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

  • PostgresChangeTracker implementing both IChangeTracker and Lyo.Health.IHealth
  • EF Core migrations in the change_tracker schema (PostgresChangeTrackerOptions.Schema)
  • Queryable history by entity, entity type, or change id (newest first)
  • DeleteForEntityAsync to 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 IChangeTrackerPostgresChangeTracker 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_tracker schema (see PostgresChangeTrackerOptions.Schema).
  • change_tracker.changes — subject (for_entity_* / SubjectEntityType), optional actor (from_entity_* / ActorEntityType), nullable tenant_id (uuid), JSON OldValues, JSON ChangedProperties, optional ChangeType / Message, and Timestamp.

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 — caller TenantId is ignored; the row stores null.
  • SingleTenantDefault (default) — caller value, falling back to Tenancy.DefaultTenantId then EntityRefOptions.DefaultTenantId.
  • MultiTenantStrict — caller must supply a non-empty TenantId or 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.Binder 10.0.5 — (direct, microsoft)
  • Lyo.Common — (transitive, lyo)
  • Microsoft.EntityFrameworkCore 10.0.5 — (transitive, microsoft)
  • Microsoft.EntityFrameworkCore.Design 10.0.5 — (transitive, microsoft)
  • Microsoft.EntityFrameworkCore.Relational 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Hosting.Abstractions 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Logging.Abstractions 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Options 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Options.ConfigurationExtensions 10.0.5 — (transitive, microsoft)
  • Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3 — (transitive, third-party)
  • System.Memory 4.6.3 — (transitive, microsoft, netstandard2.0)
  • System.Text.Json 10.0.5 — (transitive, microsoft, netstandard2.0)
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 28 8/18/2026
1.0.0 58 8/16/2026