|
|
@@ -0,0 +1,65 @@
|
|
|
+using Microsoft.Data.SqlClient;
|
|
|
+using Quadarax.Application.QLiberace.Base;
|
|
|
+using Quadarax.Application.QLiberace.Console.Commands.Base;
|
|
|
+using Quadarax.Foundation.Core.QConsole;
|
|
|
+using Quadarax.Foundation.Core.QConsole.Attributes;
|
|
|
+using Quadarax.Foundation.Core.Value;
|
|
|
+using static Quadarax.Application.QLiberace.Console.Constants.Commands;
|
|
|
+
|
|
|
+namespace Quadarax.Application.QLiberace.Console.Commands
|
|
|
+{
|
|
|
+ [CommandDefinition]
|
|
|
+ internal class DbUninstallCmd: DbContextCommand
|
|
|
+ {
|
|
|
+ #region *** Properties ***
|
|
|
+
|
|
|
+ public override string Name => DbUninstall.Name;
|
|
|
+ public override string Description => DbUninstall.Description;
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ #region *** Fields ***
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region *** Constructor ***
|
|
|
+
|
|
|
+ public DbUninstallCmd(Engine engine) : base(engine)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region *** EXECUTE ***
|
|
|
+ protected override Result OnExecute(QlbrcDbContext context)
|
|
|
+ {
|
|
|
+ WriteInfo("Connecting database...");
|
|
|
+ var resultCode = 0;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (context.Database.CanConnect())
|
|
|
+ {
|
|
|
+ WriteInfo("Deleting database...");
|
|
|
+ context.Database.EnsureDeleted();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ resultCode = DbUninstall.ReturnCodes.DatabaseNotExists;
|
|
|
+ WriteWarning("Database not exists.");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (SqlException e)
|
|
|
+ {
|
|
|
+ return HandleConnectionException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new Result(resultCode);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region *** Private operations ***
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+
|
|
|
+}
|