Przeglądaj źródła

enable EF migration, add first command to console

Dalibor Votruba 3 lat temu
rodzic
commit
1d935b54ca

+ 1 - 1
Modules/qdr.app.qlbrc.base/Entities/Interfaces/IStructSetting.cs

@@ -7,7 +7,7 @@ public interface IStructSetting
     string ModuleCode { get; set; }
     string Code { get; set; }
     string Description { get; set; }
-    string ValueTypeQN { get; set; }
+    string ValueTypeQualified { get; set; }
     string Value { get; set; }
     string IsEnabled { get; set; }
 }

+ 1 - 1
Modules/qdr.app.qlbrc.base/Entities/Setting.cs

@@ -13,7 +13,7 @@ public class Setting : QlbrcEntityTrackedWithoutId, IStructSetting
     public string Code { get; set; }
     public string Description { get; set; }
 
-    public string ValueTypeQN { get; set; }
+    public string ValueTypeQualified { get; set; }
     public string Value { get; set; }
     public string IsEnabled { get; set; }
 }

+ 34 - 0
Modules/qdr.app.qlbrc.base/QlbrcDbContext.cs

@@ -0,0 +1,34 @@
+using Microsoft.EntityFrameworkCore;
+using Quadarax.Application.QLiberace.Base.Entities;
+
+namespace Quadarax.Application.QLiberace.Base
+{
+    public class QlbrcDbContext : DbContext
+    {
+
+        #region *** Mapped entities ***
+        public DbSet<User> Users { get; set; }
+        public DbSet<Tenant> Tenants { get; set; }
+
+        public DbSet<Setting> Settings { get; set; }
+
+        #endregion
+        
+        #region *** Constructors ***
+        public QlbrcDbContext() : base()
+        {
+        }
+        public QlbrcDbContext(DbContextOptions options) : base(options)
+        {
+        }
+        #endregion
+
+
+        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+        {
+            optionsBuilder.UseSqlServer(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=QLiberace;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
+        }
+
+
+    }
+}

+ 15 - 1
Modules/qdr.app.qlbrc.base/qdr.app.qlbrc.base.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
@@ -17,4 +17,18 @@
     <Folder Include="Services\" />
   </ItemGroup>
 
+  <ItemGroup>
+    <PackageReference Include="EFCore.AutomaticMigrations" Version="6.0.4" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.9" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.9">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+  </ItemGroup>
+
 </Project>

+ 39 - 0
qdr.app.qlbrc.console/Commands/DbInstallCmd.cs

@@ -0,0 +1,39 @@
+using Quadarax.Foundation.Core.QConsole.Attributes;
+using Quadarax.Foundation.Core.QConsole;
+using Quadarax.Foundation.Core.QConsole.Command.Base;
+using Quadarax.Foundation.Core.Value;
+
+namespace Quadarax.Application.QLiberace.Console.Commands
+{
+    [CommandDefinition]
+
+    internal class DbInstallCmd : AbstractCommand
+    {
+
+        #region *** Properties ***
+
+        public override string Name => Constants.Commands.DbInstall.Name;
+        public override string Description => Constants.Commands.DbInstall.Description;
+        #endregion
+
+        #region *** Constructor ***
+
+        public DbInstallCmd(Engine engine) : base(engine)
+        {
+        }
+        #endregion
+        
+        #region *** EXECUTE ***
+
+
+        protected override Result OnExecute()
+        {
+            //TODO: ends here. Implements db_install
+            throw new NotImplementedException();
+        }
+        #endregion
+
+        #region *** Private operations ***
+        #endregion
+    }
+}

+ 19 - 0
qdr.app.qlbrc.console/Constants.cs

@@ -0,0 +1,19 @@
+namespace Quadarax.Application.QLiberace.Console
+{
+    internal class Constants
+    {
+        internal class General
+        {
+            public const string Name = "QLiberace console";
+        }
+
+        internal class Commands
+        {
+            internal class DbInstall
+            {
+                public const string Name = "db_install";
+                public const string Description = "Install application database (even if not exists)";
+            }
+        }
+    }
+}

+ 29 - 1
qdr.app.qlbrc.console/Program.cs

@@ -1,2 +1,30 @@
 // See https://aka.ms/new-console-template for more information
-Console.WriteLine("Hello, World!");
+
+using System.Reflection;
+using Quadarax.Foundation.Core.QConsole;
+using Quadarax.Foundation.Core.QConsole.Configuration;
+using Quadarax.Foundation.Core.QConsole.Context;
+using Quadarax.Foundation.Core.Reflection.Extensions;
+
+
+/*
+var options = new DbContextOptions<QlbrcDbContext>();
+
+using (var ctx = new QlbrcDbContext(options))
+{
+    var result = ctx.Database.EnsureCreated();
+    Console.WriteLine($"Database created: {result}");
+}
+*/
+
+var config = new StartupConfiguration(Quadarax.Application.QLiberace.Console.Constants.General.Name, Assembly.GetExecutingAssembly().GetName().Version);
+config.ConsoleCopyright = Assembly.GetExecutingAssembly().GetCopyright();
+config.AllowInteractive = false;
+config.WaitOnKeyInNonInteractiveMode = false;
+config.CommandDefinitionAssebmly = new[]{Assembly.GetEntryAssembly()};
+config.DisableDefaultCommands();
+config.ShowStatusOnEveryCommand = false;
+config.IsConsoleDebug = false;
+
+var console = new Engine(config, new DefualtEngineContext(), args);
+console.Start();

+ 12 - 0
qdr.app.qlbrc.console/Properties/launchSettings.json

@@ -0,0 +1,12 @@
+{
+  "profiles": {
+    "WSL": {
+      "commandName": "WSL2",
+      "distributionName": ""
+    },
+    "db_install": {
+      "commandName": "Project",
+      "commandLineArgs": "db_install"
+    }
+  }
+}

+ 14 - 0
qdr.app.qlbrc.console/qdr.app.qlbrc.console.csproj

@@ -8,10 +8,24 @@
     <RootNamespace>Quadarax.Application.QLiberace.Console</RootNamespace>
   </PropertyGroup>
 
+  <ItemGroup>
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+  </ItemGroup>
+
   <ItemGroup>
     <ProjectReference Include="..\common\qdr.app.qlbrc.common\qdr.app.qlbrc.common.csproj" />
     <ProjectReference Include="..\Common\qdr.fnd.core.qconsole\qdr.fnd.core.qconsole.csproj" />
     <ProjectReference Include="..\Common\qdr.fnd.core\qdr.fnd.core.csproj" />
+    <ProjectReference Include="..\Modules\qdr.app.qlbrc.base\qdr.app.qlbrc.base.csproj" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <None Update="readme.txt">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
 
 </Project>

+ 43 - 0
qdr.app.qlbrc.console/readme.txt

@@ -0,0 +1,43 @@
+
+ .----------------.  .----------------.  .----------------.  .----------------.  .----------------.  .----------------.  .----------------.  .----------------.  .----------------. 
+| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
+| |    ___       | || |   _____      | || |     _____    | || |   ______     | || |  _________   | || |  _______     | || |      __      | || |     ______   | || |  _________   | |
+| |  .'   '.     | || |  |_   _|     | || |    |_   _|   | || |  |_   _ \    | || | |_   ___  |  | || | |_   __ \    | || |     /  \     | || |   .' ___  |  | || | |_   ___  |  | |
+| | /  .-.  \    | || |    | |       | || |      | |     | || |    | |_) |   | || |   | |_  \_|  | || |   | |__) |   | || |    / /\ \    | || |  / .'   \_|  | || |   | |_  \_|  | |
+| | | |   | |    | || |    | |   _   | || |      | |     | || |    |  __'.   | || |   |  _|  _   | || |   |  __ /    | || |   / ____ \   | || |  | |         | || |   |  _|  _   | |
+| | \  `-'  \_   | || |   _| |__/ |  | || |     _| |_    | || |   _| |__) |  | || |  _| |___/ |  | || |  _| |  \ \_  | || | _/ /    \ \_ | || |  \ `.___.'\  | || |  _| |___/ |  | |
+| |  `.___.\__|  | || |  |________|  | || |    |_____|   | || |  |_______/   | || | |_________|  | || | |____| |___| | || ||____|  |____|| || |   `._____.'  | || | |_________|  | |
+| |              | || |              | || |              | || |              | || |              | || |              | || |              | || |              | || |              | |
+| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
+ '----------------'  '----------------'  '----------------'  '----------------'  '----------------'  '----------------'  '----------------'  '----------------'  '----------------' 
+																					CONSOLE v.0.0.0
+																				   Modified: 16.9.2022
+
+Commands list:
+* Testing *
+
+workbench		-	Runs worbench code
+
+* Database *
+db_install		-	Install application database (even if not exists)
+db_update		-	Install application database updates (must exists)
+db_clear		-	Clears all data in database (reset to factory defaults)
+db_uninstall	-	Drop database
+
+
+
+db_install
+----------
+	description:
+		Creates a brand new QLiberace database, depends on connection string definition (.config)
+
+	arguments mandatory:
+		
+	arguments optional:
+		-latest					- call db_update after create database (migrate to latest version)		
+
+	exit codes:
+		0		Ok
+		1		Cannot connect to server
+		2		Database already axists
+		100		Other unhandled exception