diff --git a/src/Tgstation.Server.Host/Configuration/DatabaseConfiguration.cs b/src/Tgstation.Server.Host/Configuration/DatabaseConfiguration.cs index 07f8690601..f397a2a61a 100644 --- a/src/Tgstation.Server.Host/Configuration/DatabaseConfiguration.cs +++ b/src/Tgstation.Server.Host/Configuration/DatabaseConfiguration.cs @@ -29,5 +29,10 @@ /// If the database should use direct table creation instead of automatic migrations. Should not be used in production! /// public bool NoMigrations { get; set; } + + /// + /// If the database should be deleted on application startup. Should not be used in production! + /// + public bool DropDatabase { get; set; } } } diff --git a/src/Tgstation.Server.Host/Models/DatabaseContext.cs b/src/Tgstation.Server.Host/Models/DatabaseContext.cs index c8401f054f..f887c2926b 100644 --- a/src/Tgstation.Server.Host/Models/DatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/DatabaseContext.cs @@ -140,6 +140,12 @@ namespace Tgstation.Server.Host.Models { Logger.LogInformation("Migrating database..."); + if (databaseConfiguration.DropDatabase) + { + Logger.LogCritical("DropDatabase configuration option set! Dropping any existing database..."); + await Database.EnsureDeletedAsync(cancellationToken).ConfigureAwait(false); + } + var wasEmpty = false; if (databaseConfiguration.NoMigrations) { diff --git a/src/Tgstation.Server.Host/appsettings.json b/src/Tgstation.Server.Host/appsettings.json index 1c91417297..e975062243 100644 --- a/src/Tgstation.Server.Host/appsettings.json +++ b/src/Tgstation.Server.Host/appsettings.json @@ -30,6 +30,7 @@ }, "Database": { "NoMigrations": false, + "DropDatabase": false, "DatabaseType": "SqlServer", "ResetAdminPassword": false, "ConnectionString": "Data Source=(local);Initial Catalog=TGS;Integrated Security=True"