Another improvement for https://www.nuget.org/account/Packages/SqlExtensionsAspire : Drop Database , Create the database, run init scripts .
Demo with Video :
The code is pretty simple: executing drop create and initialization
db.WithSqlCommand("dropCreate", $@"
USE master;
IF DB_ID(N'{dbName}') IS NOT NULL
BEGIN
ALTER DATABASE [{dbName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE [{dbName}];
END
CREATE DATABASE [{dbName}];
", ExecCommandEnum.NonQuery,new CommandOptions() { Description = $"Drop and recreate database {dbName}", IconName = "DatabaseWarning" });
return db;
db.WithCommand("reset-all", "Reset Everything", async ct =>
//code for logging
var commandService = ct.ServiceProvider.GetService(typeof(ResourceCommandService)) as ResourceCommandService;
//code for logging
var flushResult = await commandService.ExecuteCommandAsync(db.Resource, "dropCreate");
var restartResult = await commandService.ExecuteCommandAsync(db.Resource, "Startup_ExecScripts");