diff --git a/Application/Startup.cs b/Application/Startup.cs index a5b9a03..9b0db26 100644 --- a/Application/Startup.cs +++ b/Application/Startup.cs @@ -41,7 +41,7 @@ namespace PlanTempus builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule { - TelemetryConfig = ConfigurationRoot.GetSection(nameof(Core.ModuleRegistry.TelemetryConfig)).Get() + TelemetryConfig = ConfigurationRoot.GetSection(nameof(Core.ModuleRegistry.TelemetryConfig)).ToObject() }); diff --git a/Database/Core/DCL/SetupApplicationUser.cs b/Database/Core/DCL/SetupApplicationUser.cs index 9685d38..d90977b 100644 --- a/Database/Core/DCL/SetupApplicationUser.cs +++ b/Database/Core/DCL/SetupApplicationUser.cs @@ -25,7 +25,7 @@ namespace Database.Core.DCL { _db = db; } - + public void Setup(string schema = null) { throw new NotImplementedException(); diff --git a/Database/Core/DDL/SetupIdentitySystem.cs b/Database/Core/DDL/SetupIdentitySystem.cs index a85184b..c32556f 100644 --- a/Database/Core/DDL/SetupIdentitySystem.cs +++ b/Database/Core/DDL/SetupIdentitySystem.cs @@ -26,7 +26,7 @@ namespace Database.Core.DDL /// The schema name where the tables will be created. public void With(Command emptyByIntention) { - using (_transaction = _db.BeginTransaction()) + using (_transaction = _db.OpenWithTransaction()) { try { @@ -56,7 +56,7 @@ namespace Database.Core.DDL /// /// Creates the users table /// - public void CreateUsersTable() + void CreateUsersTable() { var sql = @" CREATE TABLE IF NOT EXISTS users ( @@ -80,7 +80,7 @@ namespace Database.Core.DDL /// /// Creates the tenants table /// - public void CreateTenantsTable() + void CreateTenantsTable() { var sql = @" CREATE TABLE IF NOT EXISTS tenants ( @@ -98,7 +98,7 @@ namespace Database.Core.DDL /// /// Creates the user_tenants table /// - public void CreateUserTenantsTable() + void CreateUserTenantsTable() { var sql = @" CREATE TABLE IF NOT EXISTS user_tenants ( @@ -116,7 +116,7 @@ namespace Database.Core.DDL /// /// Sets up Row Level Security (RLS) for the tenants and user_tenants tables. /// - public void SetupRLS() + void SetupRLS() { var sql = new[] { diff --git a/SetupInfrastructure/Program.cs b/SetupInfrastructure/Program.cs index 7fad4a5..7c384b8 100644 --- a/SetupInfrastructure/Program.cs +++ b/SetupInfrastructure/Program.cs @@ -19,10 +19,12 @@ namespace SetupInfrastructure internal class Program { static IContainer _container; + static ConsoleColor _backgroundColor = Console.BackgroundColor; + static ConsoleColor _foregroundColor = Console.ForegroundColor; static async Task Main(string[] args) { - + Welcome(); string userPass; try @@ -43,10 +45,17 @@ namespace SetupInfrastructure if (IsSuperAdmin()) { - var setup = _container.Resolve(); - setup.With(new Database.Core.DCL.SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" }); + Console.ForegroundColor = ConsoleColor.Green; + var setupApplicationUser = _container.Resolve(); + setupApplicationUser.With(new Database.Core.DCL.SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" }); + Console.WriteLine("Database.Core.DCL.SetupApplicationUser done!"); + Console.WriteLine(); - // SetupApplicationUser + //create new container with application user, we use that role from now. + _container = new Startup().ConfigureContainer(new Startup.ConnectionStringTemplateParameters("sathumper", "3911")); + + var setupIdentitySystem = _container.Resolve(); + setupIdentitySystem.With(new Database.Core.DDL.SetupIdentitySystem.Command()); // SetupIdentitySystem // SetupConfiguration @@ -56,7 +65,7 @@ namespace SetupInfrastructure // input configurations!!! TODO:Missing - + Console.ForegroundColor = _foregroundColor; } @@ -74,8 +83,7 @@ namespace SetupInfrastructure static bool IsSuperAdmin() { - var backgroundColor = Console.BackgroundColor; - var foregroundColor = Console.ForegroundColor; + //test db access Console.WriteLine("Testing db access..."); @@ -96,7 +104,7 @@ namespace SetupInfrastructure Console.WriteLine("TEST SUCCESSFULLY"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = backgroundColor; + Console.BackgroundColor = _backgroundColor; Console.WriteLine("-------------------------------"); Console.WriteLine(); Console.WriteLine($"Username: {username}"); @@ -118,7 +126,7 @@ namespace SetupInfrastructure Console.WriteLine("TEST WAS NOT SUCCESSFULLY"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = backgroundColor; + Console.BackgroundColor = _backgroundColor; Console.WriteLine("-------------------------------"); Console.WriteLine(); Console.WriteLine($"Username: {username}"); @@ -133,6 +141,25 @@ namespace SetupInfrastructure return false; + } + static void Welcome() + { + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine(@"__________.__ ___________ +\______ \ | _____ ___\__ ___/___ _____ ______ __ __ ______ + | ___/ | \__ \ / \| |_/ __ \ / \\____ \| | \/ ___/ + | | | |__/ __ \| | \ |\ ___/| Y Y \ |_> > | /\___ \ + |____| |____(____ /___| /____| \___ >__|_| / __/|____//____ > + \/ \/ \/ \/|__| \/ + _________ __ + / _____/ _____/ |_ __ ________ + \_____ \_/ __ \ __\ | \____ \ + / \ ___/| | | | / |_> > + /_______ /\___ >__| |____/| __/ + \/ \/ |__|"); + Console.WriteLine(); + Console.ForegroundColor = ConsoleColor.White; + } } } diff --git a/Tests/appconfiguration.dev.json b/Tests/appconfiguration.dev.json index d78a92e..9575ea2 100644 --- a/Tests/appconfiguration.dev.json +++ b/Tests/appconfiguration.dev.json @@ -1,7 +1,7 @@ { "AllowedHosts": "*", "ConnectionStrings": { - "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=sandbox;User Id=postgres;Password=3911;" + "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;" }, "ApplicationInsights": { "ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"