Add EF Core migrations and SuperAdmin seeder

- Generated InitialCreate migrations for all 5 DbContexts:
  identity, catalog, collection, bazaar, chat (separate Postgres schemas)
- Applied to pg-forge-01 (172.10.1.127) — all schemas live
- Program.cs: SeedAsync() creates SuperAdmin + Admin roles and seeds
  initial SuperAdmin account on startup if none exists
  (email/password overridable via Admin:Email / Admin:Password config)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-02-25 07:52:30 -05:00
co-authored by Claude Happy
parent ee2891d38e
commit 6f9ed0668f
16 changed files with 3017 additions and 0 deletions
+36
View File
@@ -125,4 +125,40 @@ app.MapRazorPages();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
// ── Seed roles and initial SuperAdmin ─────────────────────────────────────
await SeedAsync(app);
app.Run();
static async Task SeedAsync(WebApplication app)
{
using var scope = app.Services.CreateScope();
var roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole<Guid>>>();
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<Account>>();
var cfg = scope.ServiceProvider.GetRequiredService<IConfiguration>();
foreach (var role in new[] { "SuperAdmin", "Admin" })
{
if (!await roleManager.RoleExistsAsync(role))
await roleManager.CreateAsync(new IdentityRole<Guid>(role));
}
// Create the first SuperAdmin if none exists.
// Override via appsettings / env vars: Admin:Email Admin:Password
var email = cfg["Admin:Email"] ?? "admin@sor.local";
var password = cfg["Admin:Password"] ?? "Admin@SOR2026!";
if (await userManager.FindByEmailAsync(email) is null)
{
var account = new Account
{
UserName = email,
Email = email,
DisplayName = "Super Admin",
CreatedAt = DateTimeOffset.UtcNow,
};
var result = await userManager.CreateAsync(account, password);
if (result.Succeeded)
await userManager.AddToRoleAsync(account, "SuperAdmin");
}
}