Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
# context since the per-section split (nobodies-collective/Humans#858).
run: |
dotnet tool install --global dotnet-ef --version 10.0.*
for ctx in HumansDbContext SystemSettingsDbContext ContainersDbContext AgentDbContext ExpensesDbContext; do
for ctx in HumansDbContext SystemSettingsDbContext ContainersDbContext AgentDbContext ExpensesDbContext FinanceDbContext; do
dotnet ef migrations has-pending-model-changes \
--context "$ctx" \
--project src/Humans.Infrastructure \
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
- name: Apply per-section baselines from scratch
run: |
set -euo pipefail
for ctx in SystemSettingsDbContext ContainersDbContext AgentDbContext ExpensesDbContext; do
for ctx in SystemSettingsDbContext ContainersDbContext AgentDbContext ExpensesDbContext FinanceDbContext; do
db="humans_$(echo "$ctx" | tr '[:upper:]' '[:lower:]')"
docker exec "${{ steps.pg.outputs.container }}" \
psql -U humans -d postgres -c "CREATE DATABASE $db"
Expand All @@ -193,7 +193,7 @@ jobs:
# Belt-and-suspenders: Layer 1 already runs this in the build job,
# but re-checking after a real apply guards against any state the
# apply step might have observed differently from a static check.
for ctx in HumansDbContext SystemSettingsDbContext ContainersDbContext AgentDbContext ExpensesDbContext; do
for ctx in HumansDbContext SystemSettingsDbContext ContainersDbContext AgentDbContext ExpensesDbContext FinanceDbContext; do
dotnet ef migrations has-pending-model-changes \
--context "$ctx" \
--project src/Humans.Infrastructure \
Expand Down
40 changes: 40 additions & 0 deletions src/Humans.Infrastructure/Data/FinanceDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Humans.Domain.Entities;
using Humans.Infrastructure.Data.Configurations.Finance;
using Microsoft.EntityFrameworkCore;

namespace Humans.Infrastructure.Data;

/// <summary>
/// Per-section database context for the Finance section
/// (nobodies-collective/Humans#858): maps only <c>holded_expense_docs</c>,
/// <c>holded_category_map</c>, <c>holded_ledger_lines</c>,
/// <c>holded_creditor_contacts</c> and <c>holded_sync_states</c>, with its own
/// <c>__EFMigrationsHistory_Finance</c> table and migrations under
/// <c>Migrations/Finance/</c>. Same database, same connection — the split
/// is a code-side partition of the EF model.
/// </summary>
/// <remarks>
/// Internal-sealed like <see cref="HumansDbContext"/> (issue #750): repositories
/// are the only consumers. Configurations are applied explicitly (not by
/// assembly scanning) so this model can never accrete another section's tables.
/// </remarks>
internal sealed class FinanceDbContext(DbContextOptions<FinanceDbContext> options)
: DbContext(options)
{
public DbSet<HoldedExpenseDoc> HoldedExpenseDocs => Set<HoldedExpenseDoc>();
public DbSet<HoldedCategoryMap> HoldedCategoryMap => Set<HoldedCategoryMap>();
public DbSet<HoldedLedgerLine> HoldedLedgerLines => Set<HoldedLedgerLine>();
public DbSet<HoldedCreditorContact> HoldedCreditorContacts => Set<HoldedCreditorContact>();
public DbSet<HoldedSyncState> HoldedSyncStates => Set<HoldedSyncState>();

protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);

builder.ApplyConfiguration(new HoldedExpenseDocConfiguration());
builder.ApplyConfiguration(new HoldedCategoryMapConfiguration());
builder.ApplyConfiguration(new HoldedLedgerLineConfiguration());
builder.ApplyConfiguration(new HoldedCreditorContactConfiguration());
builder.ApplyConfiguration(new HoldedSyncStateConfiguration());
}
}
33 changes: 33 additions & 0 deletions src/Humans.Infrastructure/Data/FinanceDbContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace Humans.Infrastructure.Data;

/// <summary>
/// Design-time factory used by <c>dotnet ef … --context FinanceDbContext</c>.
/// Mirrors <see cref="HumansDbContextFactory"/>; the migrations-history table must
/// match the runtime registration so CI's from-scratch apply records baselines in
/// <c>__EFMigrationsHistory_Finance</c>.
/// </summary>
internal sealed class FinanceDbContextFactory : IDesignTimeDbContextFactory<FinanceDbContext>
{
public FinanceDbContext CreateDbContext(string[] args)
{
var connectionString =
Environment.GetEnvironmentVariable("ConnectionStrings__DefaultConnection")
?? "Host=localhost;Database=humans_design_time;Username=humans;Password=humans";

var optionsBuilder = new DbContextOptionsBuilder<FinanceDbContext>();
optionsBuilder.UseNpgsql(
connectionString,
npgsqlOptions =>
{
npgsqlOptions.UseNodaTime();
npgsqlOptions.MigrationsAssembly("Humans.Infrastructure");
npgsqlOptions.MigrationsHistoryTable("__EFMigrationsHistory_Finance");
npgsqlOptions.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery);
});

return new FinanceDbContext(optionsBuilder.Options);
}
}
6 changes: 1 addition & 5 deletions src/Humans.Infrastructure/Data/HumansDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ internal sealed class HumansDbContext(DbContextOptions<HumansDbContext> options)
public DbSet<StorePayment> StorePayments => Set<StorePayment>();
public DbSet<StoreInvoice> StoreInvoices => Set<StoreInvoice>();
public DbSet<StoreTreasurySyncState> StoreTreasurySyncStates => Set<StoreTreasurySyncState>();
public DbSet<HoldedExpenseDoc> HoldedExpenseDocs => Set<HoldedExpenseDoc>();
public DbSet<HoldedCategoryMap> HoldedCategoryMap => Set<HoldedCategoryMap>();
public DbSet<HoldedSyncState> HoldedSyncStates => Set<HoldedSyncState>();
public DbSet<HoldedLedgerLine> HoldedLedgerLines => Set<HoldedLedgerLine>();
public DbSet<HoldedCreditorContact> HoldedCreditorContacts => Set<HoldedCreditorContact>();

// Survey section
public DbSet<Survey> Surveys => Set<Survey>();
Expand All @@ -133,6 +128,7 @@ internal sealed class HumansDbContext(DbContextOptions<HumansDbContext> options)
typeof(Configurations.Containers.ContainerConfiguration).Namespace!,
typeof(Configurations.Agent.AgentConversationConfiguration).Namespace!,
typeof(Configurations.Expenses.ExpenseReportConfiguration).Namespace!,
typeof(Configurations.Finance.HoldedExpenseDocConfiguration).Namespace!,
];

protected override void OnModelCreating(ModelBuilder builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static IServiceCollection AddHumansPersistence(
services.AddSectionDbContext<ContainersDbContext>(sentinelTable: "containers");
services.AddSectionDbContext<AgentDbContext>(sentinelTable: "agent_conversations");
services.AddSectionDbContext<ExpensesDbContext>(sentinelTable: "expense_reports");
services.AddSectionDbContext<FinanceDbContext>(sentinelTable: "holded_expense_docs");

services.AddHostedService<DatabaseMigrationHostedService>();

Expand Down
Loading
Loading