Recover integrations startup migrations and enum persistence

This commit is contained in:
master
2026-03-07 02:45:40 +02:00
parent 803940bd36
commit b7cfdbd553
7 changed files with 176 additions and 28 deletions

View File

@@ -11,6 +11,8 @@ using StellaOps.Integrations.WebService.Infrastructure;
using StellaOps.Integrations.WebService.Security;
using StellaOps.Auth.ServerIntegration.Tenancy;
using StellaOps.Infrastructure.Postgres.Migrations;
using StellaOps.Infrastructure.Postgres.Options;
using StellaOps.Localization;
using StellaOps.Router.AspNet;
var builder = WebApplication.CreateBuilder(args);
@@ -27,9 +29,20 @@ var connectionString = builder.Configuration.GetConnectionString("IntegrationsDb
?? builder.Configuration.GetConnectionString("Default")
?? "Host=localhost;Database=stellaops_integrations;Username=postgres;Password=postgres";
builder.Services.Configure<PostgresOptions>(options =>
{
options.ConnectionString = connectionString;
options.SchemaName = IntegrationDbContext.DefaultSchemaName;
});
builder.Services.AddDbContext<IntegrationDbContext>(options =>
options.UseNpgsql(connectionString));
builder.Services.AddStartupMigrations(
IntegrationDbContext.DefaultSchemaName,
"Integrations.Persistence",
typeof(IntegrationDbContext).Assembly);
// Repository
builder.Services.AddScoped<IIntegrationRepository, PostgresIntegrationRepository>();
@@ -96,21 +109,6 @@ builder.TryAddStellaOpsLocalBinding("integrations");
var app = builder.Build();
app.LogStellaOpsLocalHostname("integrations");
// Auto-migrate: ensure integrations schema and tables exist on startup
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<IntegrationDbContext>();
try
{
await db.Database.EnsureCreatedAsync();
app.Logger.LogInformation("Integrations database schema ensured");
}
catch (Exception ex)
{
app.Logger.LogWarning(ex, "Integrations database EnsureCreated failed (may already exist)");
}
}
// Configure pipeline
if (app.Environment.IsDevelopment())
{

View File

@@ -18,6 +18,7 @@
<ProjectReference Include="..\__Plugins\StellaOps.Integrations.Plugin.Harbor\StellaOps.Integrations.Plugin.Harbor.csproj" />
<ProjectReference Include="..\__Plugins\StellaOps.Integrations.Plugin.InMemory\StellaOps.Integrations.Plugin.InMemory.csproj" />
<ProjectReference Include="..\..\__Libraries\StellaOps.Plugin\StellaOps.Plugin.csproj" />
<ProjectReference Include="..\..\__Libraries\StellaOps.Infrastructure.Postgres\StellaOps.Infrastructure.Postgres.csproj" />
<ProjectReference Include="..\..\Router\__Libraries\StellaOps.Messaging\StellaOps.Messaging.csproj" />
<ProjectReference Include="..\..\Authority\StellaOps.Authority\StellaOps.Auth.ServerIntegration\StellaOps.Auth.ServerIntegration.csproj" />
<ProjectReference Include="..\..\__Libraries\StellaOps.Localization\StellaOps.Localization.csproj" />