|
@@ -1,19 +1,27 @@
|
|
|
-using Quadarax.Foundation.Core.QConsole.Attributes;
|
|
|
|
|
|
|
+using Quadarax.Application.QLiberace.Base;
|
|
|
|
|
+using Quadarax.Application.QLiberace.Console.Commands.Base;
|
|
|
|
|
+using Quadarax.Foundation.Core.QConsole.Attributes;
|
|
|
using Quadarax.Foundation.Core.QConsole;
|
|
using Quadarax.Foundation.Core.QConsole;
|
|
|
-using Quadarax.Foundation.Core.QConsole.Command.Base;
|
|
|
|
|
|
|
+using Quadarax.Foundation.Core.QConsole.Argument;
|
|
|
|
|
+using Quadarax.Foundation.Core.QConsole.Value;
|
|
|
using Quadarax.Foundation.Core.Value;
|
|
using Quadarax.Foundation.Core.Value;
|
|
|
|
|
|
|
|
namespace Quadarax.Application.QLiberace.Console.Commands
|
|
namespace Quadarax.Application.QLiberace.Console.Commands
|
|
|
{
|
|
{
|
|
|
[CommandDefinition]
|
|
[CommandDefinition]
|
|
|
|
|
|
|
|
- internal class DbInstallCmd : AbstractCommand
|
|
|
|
|
|
|
+ internal class DbInstallCmd : DbMigrationCommand
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
#region *** Properties ***
|
|
#region *** Properties ***
|
|
|
|
|
|
|
|
public override string Name => Constants.Commands.DbInstall.Name;
|
|
public override string Name => Constants.Commands.DbInstall.Name;
|
|
|
public override string Description => Constants.Commands.DbInstall.Description;
|
|
public override string Description => Constants.Commands.DbInstall.Description;
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+ #region *** Fields ***
|
|
|
|
|
+
|
|
|
|
|
+ private bool _isLatestUpdateEnabled;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Constructor ***
|
|
#region *** Constructor ***
|
|
@@ -24,16 +32,49 @@ namespace Quadarax.Application.QLiberace.Console.Commands
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** EXECUTE ***
|
|
#region *** EXECUTE ***
|
|
|
|
|
+ protected override Result OnExecute(QlbrcDbContext context)
|
|
|
|
|
+ {
|
|
|
|
|
+ WriteInfo("Ensuring database...");
|
|
|
|
|
+ if (context.Database.EnsureCreated())
|
|
|
|
|
+ WriteInfo("Database already exists.");
|
|
|
|
|
+ else
|
|
|
|
|
+ WriteInfo("Database created.");
|
|
|
|
|
|
|
|
|
|
+ if (_isLatestUpdateEnabled)
|
|
|
|
|
+ {
|
|
|
|
|
+ WriteInfo("Checking pending migrations.");
|
|
|
|
|
+ if (CheckPendingMigrations(context))
|
|
|
|
|
+ {
|
|
|
|
|
+ WriteInfo("New pending migrations detected.");
|
|
|
|
|
+ ApplyMigration(context);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ WriteInfo("Nothing found.");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- protected override Result OnExecute()
|
|
|
|
|
- {
|
|
|
|
|
- //TODO: ends here. Implements db_install
|
|
|
|
|
- throw new NotImplementedException();
|
|
|
|
|
|
|
+ return new Result();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Private operations ***
|
|
#region *** Private operations ***
|
|
|
|
|
+ protected override void OnValidateArguments()
|
|
|
|
|
+ {
|
|
|
|
|
+ base.OnValidateArguments();
|
|
|
|
|
+ if (ContainsArgument(Constants.Commands.DbInstall.Arguments.Latest.Name))
|
|
|
|
|
+ _isLatestUpdateEnabled = GetArgumentValueOrDefault<bool>(Constants.Commands.DbInstall.Arguments.Latest.Name);
|
|
|
|
|
+ }
|
|
|
|
|
+ protected override IEnumerable<AbstractArgument> OnSetupArguments()
|
|
|
|
|
+ {
|
|
|
|
|
+ var arguments = new List<AbstractArgument>(base.OnSetupArguments());
|
|
|
|
|
+ arguments.Add(new FlagArgument(Constants.Commands.DbInstall.Arguments.Latest.Name,
|
|
|
|
|
+ Constants.Commands.DbInstall.Arguments.Latest.Description,
|
|
|
|
|
+ Constants.Commands.DbInstall.Arguments.Latest.Hint, false));
|
|
|
|
|
+ return arguments;
|
|
|
|
|
+ }
|
|
|
#endregion
|
|
#endregion
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|