mock data
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
// Sprint: SPRINT_4100_0006_0005 - Admin Utility Integration
|
||||
|
||||
using System.CommandLine;
|
||||
using StellaOps.Cli.Services;
|
||||
using StellaOps.Infrastructure.Postgres.Migrations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace StellaOps.Cli.Commands.Admin;
|
||||
|
||||
@@ -32,6 +36,9 @@ internal static class AdminCommandGroup
|
||||
admin.Add(BuildAuditCommand(verboseOption));
|
||||
admin.Add(BuildDiagnosticsCommand(verboseOption));
|
||||
|
||||
// Demo data seeding
|
||||
admin.Add(BuildSeedDemoCommand(services, verboseOption, cancellationToken));
|
||||
|
||||
return admin;
|
||||
}
|
||||
|
||||
@@ -337,6 +344,140 @@ internal static class AdminCommandGroup
|
||||
return system;
|
||||
}
|
||||
|
||||
#region Demo Data Seeding
|
||||
|
||||
/// <summary>
|
||||
/// Build the 'admin seed-demo' command.
|
||||
/// Seeds all databases with realistic demo data using S001_demo_seed.sql migrations.
|
||||
/// </summary>
|
||||
private static Command BuildSeedDemoCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var seedDemo = new Command("seed-demo", "Seed all databases with demo data for exploration and demos");
|
||||
|
||||
var moduleOption = new Option<string?>("--module")
|
||||
{
|
||||
Description = "Seed a specific module only (Authority, Scheduler, Concelier, Policy, Notify, Excititor)"
|
||||
};
|
||||
var connectionOption = new Option<string?>("--connection")
|
||||
{
|
||||
Description = "PostgreSQL connection string override"
|
||||
};
|
||||
var dryRunOption = new Option<bool>("--dry-run")
|
||||
{
|
||||
Description = "List seed files without executing"
|
||||
};
|
||||
var confirmOption = new Option<bool>("--confirm")
|
||||
{
|
||||
Description = "Required flag to confirm data insertion (safety gate)"
|
||||
};
|
||||
|
||||
seedDemo.Add(moduleOption);
|
||||
seedDemo.Add(connectionOption);
|
||||
seedDemo.Add(dryRunOption);
|
||||
seedDemo.Add(confirmOption);
|
||||
|
||||
seedDemo.SetAction(async (parseResult, ct) =>
|
||||
{
|
||||
var module = parseResult.GetValue(moduleOption);
|
||||
var connection = parseResult.GetValue(connectionOption);
|
||||
var dryRun = parseResult.GetValue(dryRunOption);
|
||||
var confirm = parseResult.GetValue(confirmOption);
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
if (!dryRun && !confirm)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]ERROR:[/] This command inserts demo data into databases.");
|
||||
AnsiConsole.MarkupLine("[dim]Use --confirm to proceed, or --dry-run to preview seed files.[/]");
|
||||
AnsiConsole.MarkupLine("[dim]Example: stella admin seed-demo --confirm[/]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var modules = MigrationModuleRegistry.GetModules(module).ToList();
|
||||
if (modules.Count == 0)
|
||||
{
|
||||
AnsiConsole.MarkupLine(
|
||||
$"[red]No modules matched '{module}'.[/] Available: {string.Join(", ", MigrationModuleRegistry.ModuleNames)}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var migrationService = services.GetRequiredService<MigrationCommandService>();
|
||||
|
||||
AnsiConsole.MarkupLine($"[bold]Stella Ops Demo Data Seeder[/]");
|
||||
AnsiConsole.MarkupLine($"Modules: {string.Join(", ", modules.Select(m => m.Name))}");
|
||||
AnsiConsole.MarkupLine($"Mode: {(dryRun ? "[yellow]DRY RUN[/]" : "[green]EXECUTE[/]")}");
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
var totalApplied = 0;
|
||||
var totalSkipped = 0;
|
||||
var failedModules = new List<string>();
|
||||
|
||||
foreach (var mod in modules)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await migrationService
|
||||
.RunAsync(mod, connection, MigrationCategory.Seed, dryRun, timeoutSeconds: 300, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
AnsiConsole.MarkupLine($"[red]{Markup.Escape(mod.Name)} FAILED:[/] {result.ErrorMessage}");
|
||||
failedModules.Add(mod.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
totalApplied += result.AppliedCount;
|
||||
totalSkipped += result.SkippedCount;
|
||||
|
||||
var mode = dryRun ? "DRY-RUN" : "SEEDED";
|
||||
var statusColor = result.AppliedCount > 0 ? "green" : "dim";
|
||||
AnsiConsole.MarkupLine(
|
||||
$"[{statusColor}]{Markup.Escape(mod.Name)}[/] {mode}: applied={result.AppliedCount} skipped={result.SkippedCount} ({result.DurationMs}ms)");
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
foreach (var migration in result.AppliedMigrations.OrderBy(m => m.Name))
|
||||
{
|
||||
AnsiConsole.MarkupLine($" [dim]{migration.Name} ({migration.DurationMs}ms)[/]");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.MarkupLine($"[red]{Markup.Escape(mod.Name)} ERROR:[/] {ex.Message}");
|
||||
failedModules.Add(mod.Name);
|
||||
}
|
||||
}
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
if (failedModules.Count > 0)
|
||||
{
|
||||
AnsiConsole.MarkupLine($"[red]Failed modules: {string.Join(", ", failedModules)}[/]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dryRun)
|
||||
{
|
||||
AnsiConsole.MarkupLine($"[yellow]DRY RUN complete.[/] {totalApplied} seed migration(s) would be applied.");
|
||||
AnsiConsole.MarkupLine("[dim]Run with --confirm to execute.[/]");
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiConsole.MarkupLine($"[green]Demo data seeded successfully.[/] applied={totalApplied} skipped={totalSkipped}");
|
||||
AnsiConsole.MarkupLine("[dim]Open the UI to explore the demo data.[/]");
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
return seedDemo;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sprint: SPRINT_20260118_014_CLI_evidence_remaining_consolidation (CLI-E-005)
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user