Lyo.HomeInventory.Postgres
2.0.0
See the version list below for details.
dotnet add package Lyo.HomeInventory.Postgres --version 2.0.0
NuGet\Install-Package Lyo.HomeInventory.Postgres -Version 2.0.0
<PackageReference Include="Lyo.HomeInventory.Postgres" Version="2.0.0" />
<PackageVersion Include="Lyo.HomeInventory.Postgres" Version="2.0.0" />
<PackageReference Include="Lyo.HomeInventory.Postgres" />
paket add Lyo.HomeInventory.Postgres --version 2.0.0
#r "nuget: Lyo.HomeInventory.Postgres, 2.0.0"
#:package Lyo.HomeInventory.Postgres@2.0.0
#addin nuget:?package=Lyo.HomeInventory.Postgres&version=2.0.0
#tool nuget:?package=Lyo.HomeInventory.Postgres&version=2.0.0
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 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"). Registering the store exposes a database liveness probe. - Schema constant:PostgresHomeInventoryOptions.Schema = "home_inventory". Default configuration section:PostgresHomeInventory(PostgresHomeInventoryOptions.SectionName).
Examples
Register the store
services.AddPostgresHomeInventoryStore(new PostgresHomeInventoryOptions {
ConnectionString = "...",
EnableAutoMigrations = true
});
appsettings.json
{
"PostgresHomeInventory": {
"ConnectionString": "Host=localhost;Database=lyo;...",
"EnableAutoMigrations": true
}
}
Bind from configuration
services.AddPostgresHomeInventoryStoreFromConfiguration(configuration);
Service registration
AddHomeInventoryDbContextFactory(Action<PostgresHomeInventoryOptions>)/AddHomeInventoryDbContextFactory(PostgresHomeInventoryOptions)register theIDbContextFactory<HomeInventoryDbContext>only. Handy for tooling and migrations.AddHomeInventoryDbContextFactoryFromConfiguration(IConfiguration, string sectionName = PostgresHomeInventoryOptions.SectionName)does the same, bound from configuration.AddPostgresHomeInventoryStore(Action<PostgresHomeInventoryOptions>)/AddPostgresHomeInventoryStore(PostgresHomeInventoryOptions)register the DbContext factory and theIHomeInventoryStoresingleton.AddPostgresHomeInventoryStoreFromConfiguration(IConfiguration, string sectionName = PostgresHomeInventoryOptions.SectionName)registers the store by binding configuration.
From configuration
The same registration from configuration:
Migration 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.
Tenant isolation
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. Those are 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 policy 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.Configuration(direct, lyo)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)Lyo.Common.Core(transitive, lyo)Microsoft.Bcl.AsyncInterfaces10.0.5(transitive, microsoft, netstandard2.0)Microsoft.EntityFrameworkCore.Relational10.0.5(transitive, microsoft)Microsoft.Extensions.Configuration.Binder10.0.5(transitive, microsoft)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5(transitive, microsoft)Microsoft.Extensions.Hosting.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.Configuration (>= 2.0.0)
- Lyo.EntityReference.Models (>= 2.0.0)
- Lyo.EntityReference.Postgres (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Health (>= 2.0.0)
- Lyo.HomeInventory (>= 2.0.0)
- Lyo.Postgres (>= 2.0.0)
- Microsoft.EntityFrameworkCore (>= 10.0.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Lyo.HomeInventory.Postgres:
| Package | Downloads |
|---|---|
|
Lyo.HomeInventory.Api
HTTP API surface for Lyo HomeInventory: categories, locations, items, and movements. |
GitHub repositories
This package is not used by any popular GitHub repositories.