Skip to content

Commit

Permalink
Moved drop DB command to database resource
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmackay committed Nov 6, 2024
1 parent 7c5e297 commit d6a4938
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions tools/AppHost/Commands/SqlServerCommandExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

namespace AppHost.Commands;

public static class SqlServerCommandExt
public static class SqlServerDatabaseCommandExt
{
public static IResourceBuilder<SqlServerServerResource> WithDropDatabaseCommand(
this IResourceBuilder<SqlServerServerResource> builder)
public static IResourceBuilder<SqlServerDatabaseResource> WithDropDatabaseCommand(
this IResourceBuilder<SqlServerDatabaseResource> builder)
{
builder.WithCommand(
"drop-database",
"Drop Database",
async context =>
{
var connectionString = await builder.Resource.GetConnectionStringAsync();
var connectionString = await builder.Resource.ConnectionStringExpression.GetValueAsync(default);
ArgumentException.ThrowIfNullOrWhiteSpace(connectionString);

var optionsBuilder = new DbContextOptionsBuilder<DbContext>();
Expand Down
4 changes: 2 additions & 2 deletions tools/AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Ensure the port doesn't conflict with other docker containers (or remove it altogether)
var sqlServer = builder
.AddSqlServer("sql", port: 1800)
.WithDropDatabaseCommand()
.WithLifetime(ContainerLifetime.Persistent);

var db = sqlServer
.AddDatabase("clean-architecture");
.AddDatabase("clean-architecture")
.WithDropDatabaseCommand();

var migrationService = builder.AddProject<MigrationService>("migrations")
.WithReference(db)
Expand Down
2 changes: 1 addition & 1 deletion tools/MigrationService/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

var warehouseInitializer = scope.ServiceProvider.GetRequiredService<ApplicationDbContextInitializer>();
await warehouseInitializer.EnsureDatabaseAsync(stoppingToken);
await warehouseInitializer.CreateSchemaAsync(true, stoppingToken);
await warehouseInitializer.CreateSchemaAsync(false, stoppingToken);

if (environment.IsDevelopment())
{
Expand Down

0 comments on commit d6a4938

Please sign in to comment.