Files
git.stella-ops.org/src/Findings/StellaOps.Findings.Ledger/Infrastructure/Postgres/FindingsLedgerDbContextFactory.cs
master 65106afe4c refactor: DB schema fixes + container renames + compose include + audit sprint
- FindingsLedger: change schema from public to findings (V3-01)
- Add 9 migration module plugins: RiskEngine, Replay, ExportCenter, Integrations, Signer, IssuerDirectory, Workflow, PacksRegistry, OpsMemory (V4-01 to V4-09)
- Remove 16 redundant inline CREATE SCHEMA patterns (V4-10)
- Rename export→export-web, excititor→excititor-web for consistency
- Compose stella-ops.yml: thin wrapper using include: directive
- Fix dead /api/v1/jobengine/* gateway routes → release-orchestrator/packsregistry
- Scheduler plugin architecture: ISchedulerJobPlugin + ScanJobPlugin + DoctorJobPlugin
- Create unified audit sink sprint plan
- VulnExplorer integration tests + gap analysis

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 16:10:36 +03:00

42 lines
1.5 KiB
C#

using Microsoft.EntityFrameworkCore;
using Npgsql;
using StellaOps.Findings.Ledger.EfCore.CompiledModels;
using StellaOps.Findings.Ledger.EfCore.Context;
namespace StellaOps.Findings.Ledger.Infrastructure.Postgres;
internal static class FindingsLedgerDbContextFactory
{
public const string DefaultSchemaName = "findings";
public static FindingsLedgerDbContext Create(NpgsqlConnection connection, int commandTimeoutSeconds, string schemaName)
{
var normalizedSchema = string.IsNullOrWhiteSpace(schemaName)
? DefaultSchemaName
: schemaName.Trim();
var optionsBuilder = new DbContextOptionsBuilder<FindingsLedgerDbContext>()
.UseNpgsql(connection, npgsql => npgsql.CommandTimeout(commandTimeoutSeconds));
if (string.Equals(normalizedSchema, DefaultSchemaName, StringComparison.Ordinal))
{
// Use the static compiled model when schema mapping matches the default model.
// Guard: only apply if compiled model has entity types registered.
try
{
var compiledModel = FindingsLedgerDbContextModel.Instance;
if (compiledModel.GetEntityTypes().Any())
{
optionsBuilder.UseModel(compiledModel);
}
}
catch
{
// Fall back to reflection model if compiled model is not fully initialized.
}
}
return new FindingsLedgerDbContext(optionsBuilder.Options, normalizedSchema);
}
}