Skip to content

Commit

Permalink
Add database delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Sep 15, 2024
1 parent b0ac42e commit 1dc0d66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Threading.Tasks;
using Edelstein.Common.Database;
using Microsoft.EntityFrameworkCore;
using Spectre.Console;
using Spectre.Console.Cli;

namespace Edelstein.Application.Server.Commands;

public class DatabaseDeleteCommand(
IDbContextFactory<GameDbContext> factory
) : AsyncCommand<DatabaseDeleteCommand.Settings>
{
public class Settings : CommandSettings;

public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
{
await using var db = await factory.CreateDbContextAsync();

await db.Database.EnsureDeletedAsync();
AnsiConsole.WriteLine("Database deleted");
return 0;
}
}
3 changes: 3 additions & 0 deletions src/app/Edelstein.Application.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
c2
.AddCommand<DatabaseMigrateCommand>("migrate")
.WithDescription("Migrates the current database");
c2
.AddCommand<DatabaseDeleteCommand>("delete")
.WithDescription("Deletes the current database");
})
.WithAlias("db");
Expand Down

0 comments on commit 1dc0d66

Please sign in to comment.