Fixed scanning issue. Updated worker.
This commit is contained in:
@@ -11,16 +11,30 @@ using System.CommandLine;
|
||||
|
||||
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
// Build a single configuration pipeline
|
||||
builder.Configuration
|
||||
.SetBasePath(builder.Environment.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
|
||||
// Add user secrets (works regardless of environment when optional: true)
|
||||
.AddUserSecrets(typeof(Program).Assembly, optional: true)
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
// Pull the connection string from config (appsettings or secrets or env)
|
||||
string connectionString = builder.Configuration.GetConnectionString("AppDb")
|
||||
?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb");
|
||||
|
||||
//builder.Services.AddSerilog(o => o
|
||||
// .WriteTo.Console()
|
||||
// .MinimumLevel.Information());
|
||||
|
||||
builder.Services
|
||||
.AddApplication()
|
||||
.AddInfrastructure();
|
||||
.AddInfrastructure()
|
||||
.AddMemoryCache();
|
||||
|
||||
string connectionString = builder.Configuration.GetConnectionString("AppDb")
|
||||
?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb2");
|
||||
//string connectionString = builder.Configuration.GetConnectionString("AppDb")
|
||||
// ?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb");
|
||||
|
||||
builder.Services.AddDbContextFactory<AppDbContext>(optionsBuilder =>
|
||||
optionsBuilder
|
||||
@@ -106,4 +120,21 @@ rootCommand.Add(scan);
|
||||
|
||||
//rootCommand.SetAction(async (parseResult, cancellationToken) => await rootCommand.InvokeAsync("scan"));
|
||||
|
||||
Command schemaDumpCommand = new("schema-dump", "Emit EF model as a full create script (desired.sql)");
|
||||
|
||||
schemaDumpCommand.SetAction(async (parseResult, cancellationToken) =>
|
||||
{
|
||||
using var host = builder.Build();
|
||||
await using var scope = host.Services.CreateAsyncScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
|
||||
var sql = db.Database.GenerateCreateScript();
|
||||
var outPath = Path.GetFullPath("desired.sql");
|
||||
await File.WriteAllTextAsync(outPath, sql);
|
||||
|
||||
Console.WriteLine($"[OK] Wrote EF model create script to: {outPath}");
|
||||
});
|
||||
|
||||
rootCommand.Add(schemaDumpCommand);
|
||||
|
||||
return await rootCommand.Parse(args).InvokeAsync();
|
||||
Reference in New Issue
Block a user