Lyo.HomeInventory.Postgres
1.0.1
dotnet add package Lyo.HomeInventory.Postgres --version 1.0.1
NuGet\Install-Package Lyo.HomeInventory.Postgres -Version 1.0.1
<PackageReference Include="Lyo.HomeInventory.Postgres" Version="1.0.1" />
<PackageVersion Include="Lyo.HomeInventory.Postgres" Version="1.0.1" />
<PackageReference Include="Lyo.HomeInventory.Postgres" />
paket add Lyo.HomeInventory.Postgres --version 1.0.1
#r "nuget: Lyo.HomeInventory.Postgres, 1.0.1"
#:package Lyo.HomeInventory.Postgres@1.0.1
#addin nuget:?package=Lyo.HomeInventory.Postgres&version=1.0.1
#tool nuget:?package=Lyo.HomeInventory.Postgres&version=1.0.1
Lyo.HomeInventory.Postgres
EF Core implementation of IHomeInventoryStore backed by PostgreSQL.
HomeInventoryDbContextmodels items, categories, locations, stock, and the movement ledger (seeDatabase/*plus the migrations snapshot for the authoritative FK / cascade story). -PostgresHomeInventoryStoreruns stock adjustments and transfers inside database transactions (BeginTransactionAsync) so the stock row and its paired movement row commit atomically. - The store also implementsLyo.Health.IHealth(HealthCheckName = "home-inventory-postgres"), so registering the store exposes a database liveness probe. - Schema constant:PostgresHomeInventoryOptions.Schema = "home_inventory". The default configuration section name isPostgresHomeInventory(PostgresHomeInventoryOptions.SectionName).
Examples
Usage
services.AddPostgresHomeInventoryStore(new PostgresHomeInventoryOptions {
ConnectionString = "...",
EnableAutoMigrations = true
});
Usage (2)
{
"PostgresHomeInventory": {
"ConnectionString": "Host=localhost;Database=lyo;...",
"EnableAutoMigrations": true
}
}
Usage (3)
services.AddPostgresHomeInventoryStoreFromConfiguration(configuration);
DI extensions
AddHomeInventoryDbContextFactory(Action<PostgresHomeInventoryOptions>)/AddHomeInventoryDbContextFactory(PostgresHomeInventoryOptions)— register only theIDbContextFactory<HomeInventoryDbContext>(useful for tooling and migrations).AddHomeInventoryDbContextFactoryFromConfiguration(IConfiguration, string sectionName = PostgresHomeInventoryOptions.SectionName)— same, bound from configuration.AddPostgresHomeInventoryStore(Action<PostgresHomeInventoryOptions>)/AddPostgresHomeInventoryStore(PostgresHomeInventoryOptions)— register the DbContext factory and theIHomeInventoryStoresingleton.AddPostgresHomeInventoryStoreFromConfiguration(IConfiguration, string sectionName = PostgresHomeInventoryOptions.SectionName)— register the store using configuration binding.
Usage
Or with configuration:
Migrations hygiene
Coordinate schema changes with any API adapters — especially when adjusting movement uniqueness constraints or the (ItemId, LocationId) composite key on stock (which must stay aligned with UpsertStockAsync semantics). Avoid editing historical migrations retroactively unless you intentionally squash, because that breaks checksums already deployed in production CI.
Tenancy
All five entities (HomeItemEntity, HomeCategoryEntity, HomeLocationEntity, HomeItemStockEntity, HomeItemMovementEntity) carry a nullable tenant_id (uuid)
column with a filtered ix_home_inv_<entity>_tenant index. OwnerEntityType / OwnerEntityId on items still describe which user/household owns the item within a
tenant — they're orthogonal concepts.
IHomeInventoryStore accepts an explicit Guid? tenantId on every method and runs it through TenancyResolver.Resolve using the policy configured in
PostgresHomeInventoryOptions.Tenancy (inheriting from EntityRefOptions.Mode when unset). Stock and movement transactional methods (AdjustStockAsync,
TransferStockAsync) resolve the tenant once and stamp it on every row written in the transaction:
SystemOnly— every row is persisted withtenant_id = NULL.SingleTenantDefault(default) — caller value, falling back toTenancy.DefaultTenantIdthenEntityRefOptions.DefaultTenantId.MultiTenantStrict— caller must supply a non-emptytenantIdor the store throws.
See Lyo.EntityReference.Postgres for the full matrix.
{
"PostgresHomeInventory": {
"ConnectionString": "Host=localhost;Database=home_inventory;...",
"Tenancy": { "Mode": "MultiTenantStrict" }
}
}
Error model
- Deleting a category fails with an operation exception when child categories or assigned items still exist.
- Deleting a location fails when child locations, stock rows, or movement history reference it.
AdjustStockAsyncfails when an adjustment would driveQuantityOnHandnegative, or when called against a non-existent stock row with a non-positive delta.TransferStockAsyncfails whenquantity <= 0, the source row is missing, or the source has insufficient on-hand quantity.
See also
Lyo.HomeInventory— interface, records, and enum vocabulary.
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.EntityReference.Models— (direct, lyo)Lyo.EntityReference.Postgres— (direct, lyo)Lyo.Exceptions— (direct, lyo)Lyo.Health— (direct, lyo)Lyo.HomeInventory— (direct, lyo)Lyo.Postgres— (direct, lyo)Microsoft.EntityFrameworkCore10.0.5— (direct, microsoft)Microsoft.EntityFrameworkCore.Design10.0.5— (direct, microsoft)Microsoft.Extensions.Configuration.Binder10.0.5— (direct, microsoft)Lyo.Common— (transitive, lyo)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.EntityReference.Models (>= 1.0.1)
- Lyo.EntityReference.Postgres (>= 1.0.1)
- Lyo.Exceptions (>= 1.0.1)
- Lyo.Health (>= 1.0.1)
- Lyo.HomeInventory (>= 1.0.1)
- Lyo.Postgres (>= 1.0.1)
- Microsoft.EntityFrameworkCore (>= 10.0.5)
- 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.