diff --git a/Database/Identity/DbSetup.cs b/Database/Identity/DbInfrastructureSetup.cs similarity index 94% rename from Database/Identity/DbSetup.cs rename to Database/Identity/DbInfrastructureSetup.cs index 09d2fe4..db86e7c 100644 --- a/Database/Identity/DbSetup.cs +++ b/Database/Identity/DbInfrastructureSetup.cs @@ -3,17 +3,17 @@ using System.Data; namespace Database.Identity { - public class DbSetup + public class DbInfrastructureSetup { private readonly IDbConnection _db; string _schema; - public DbSetup(IDbConnection db) + public DbInfrastructureSetup(IDbConnection db) { _db = db; } - public async Task CreateDatabase(string schema) + public async Task CreateDatabaseWithSchema(string schema) { _schema = schema; diff --git a/PlanTempus.sln b/PlanTempus.sln index d85aa5c..d2e53b1 100644 --- a/PlanTempus.sln +++ b/PlanTempus.sln @@ -12,12 +12,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Database", "Database\Databa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestPostgresql", "TestPostgresLISTEN\TestPostgresql.csproj", "{743EF625-6C74-419C-A492-AA069956F471}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetupInfrastructure", "SetupInfrastructure\SetupInfrastructure.csproj", "{48300227-BCBB-45A3-8359-9064DA85B1F9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {48300227-BCBB-45A3-8359-9064DA85B1F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48300227-BCBB-45A3-8359-9064DA85B1F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48300227-BCBB-45A3-8359-9064DA85B1F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48300227-BCBB-45A3-8359-9064DA85B1F9}.Release|Any CPU.Build.0 = Release|Any CPU {743EF625-6C74-419C-A492-AA069956F471}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {743EF625-6C74-419C-A492-AA069956F471}.Debug|Any CPU.Build.0 = Debug|Any CPU {743EF625-6C74-419C-A492-AA069956F471}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -46,4 +52,3 @@ Global SolutionGuid = {AF20C396-63E0-48AE-A4EA-5D24A20C4845} EndGlobalSection EndGlobal -Global diff --git a/SetupInfrastructure/CreateRole.txt b/SetupInfrastructure/CreateRole.txt new file mode 100644 index 0000000..23a4a73 --- /dev/null +++ b/SetupInfrastructure/CreateRole.txt @@ -0,0 +1,13 @@ +CREATE ROLE sathumper WITH + CREATEROLE + CREATEDB + LOGIN + PASSWORD ''; + +CREATE SCHEMA ptmain; +GRANT USAGE, CREATE ON SCHEMA ptmain TO sathumper; +GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA ptmain TO sathumper; +GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA ptmain TO sathumper; +ALTER DEFAULT PRIVILEGES IN SCHEMA ptmain +GRANT ALL PRIVILEGES ON TABLES TO sathumper; + diff --git a/SetupInfrastructure/Program.cs b/SetupInfrastructure/Program.cs new file mode 100644 index 0000000..0934dda --- /dev/null +++ b/SetupInfrastructure/Program.cs @@ -0,0 +1,22 @@ +namespace SetupInfrastructure +{ + /// + /// SETUP APPLICATION USER NAMED sathumper + /// + /// This should be handled on the Postgresql db server with a superadmin or similar. + /// + /// Execute SQL CreateRole.txt + /// + /// After that is executed it is time for running this main program + /// Remember to use the newly created sathumper + /// "ConnectionStrings": { + /// "ptdb": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id=sathumper;Password=;" + /// + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } +} diff --git a/SetupInfrastructure/SetupInfrastructure.csproj b/SetupInfrastructure/SetupInfrastructure.csproj new file mode 100644 index 0000000..e06d113 --- /dev/null +++ b/SetupInfrastructure/SetupInfrastructure.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + Always + + + + diff --git a/SetupInfrastructure/appsettings.json b/SetupInfrastructure/appsettings.json new file mode 100644 index 0000000..bd7624b --- /dev/null +++ b/SetupInfrastructure/appsettings.json @@ -0,0 +1,9 @@ +{ + "AllowedHosts": "*", + "ConnectionStrings": { + "ptdb": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id=postgres;Password=3911;" + }, + "ApplicationInsights": { + "ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/" + } +} \ No newline at end of file diff --git a/SqlManagement/.dbeaver/.project-metadata.json.bak b/SqlManagement/.dbeaver/.project-metadata.json.bak new file mode 100644 index 0000000..219bc44 --- /dev/null +++ b/SqlManagement/.dbeaver/.project-metadata.json.bak @@ -0,0 +1 @@ +{"resources":{"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"}}} \ No newline at end of file diff --git a/SqlManagement/.dbeaver/project-metadata.json b/SqlManagement/.dbeaver/project-metadata.json new file mode 100644 index 0000000..c517be1 --- /dev/null +++ b/SqlManagement/.dbeaver/project-metadata.json @@ -0,0 +1 @@ +{"resources":{"Scripts/Script-2.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"},"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"}}} \ No newline at end of file diff --git a/SqlManagement/Scripts/Script-2.sql b/SqlManagement/Scripts/Script-2.sql index d3856a0..2d5b856 100644 --- a/SqlManagement/Scripts/Script-2.sql +++ b/SqlManagement/Scripts/Script-2.sql @@ -1,4 +1,7 @@ + + + GRANT USAGE, CREATE ON SCHEMA swp TO sathumper; ALTER DEFAULT PRIVILEGES IN SCHEMA swp diff --git a/SqlManagement/Scripts/grant-privileges.sql b/SqlManagement/Scripts/grant-privileges.sql new file mode 100644 index 0000000..d9ed48d --- /dev/null +++ b/SqlManagement/Scripts/grant-privileges.sql @@ -0,0 +1,45 @@ +CREATE ROLE sathumper WITH + CREATEROLE + CREATEDB + LOGIN + PASSWORD '3911'; + +CREATE SCHEMA ptmain; +GRANT USAGE, CREATE ON SCHEMA ptmain TO sathumper; +GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA ptmain TO sathumper; +GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA ptmain TO sathumper; +ALTER DEFAULT PRIVILEGES IN SCHEMA ptmain +GRANT ALL PRIVILEGES ON TABLES TO sathumper; + + +-- prod.app_configuration definition + +-- Drop table + +-- DROP TABLE prod.app_configuration; + +CREATE TABLE prod.app_configuration ( + + id bigserial NOT NULL, + + "key" varchar(255) NOT NULL, + + value text NULL, + + "label" varchar(255) NULL, + + content_type varchar(255) DEFAULT 'text/plain'::character varying NULL, + + expires_at timestamptz NULL, + + created_at timestamptz DEFAULT CURRENT_TIMESTAMP NULL, + + modified_at timestamptz DEFAULT CURRENT_TIMESTAMP NULL, + + etag uuid DEFAULT gen_random_uuid() NULL, + + CONSTRAINT app_configuration_pkey PRIMARY KEY (id) + +); + +CREATE UNIQUE INDEX idx_prod_unique_key_label ON prod.app_configuration USING btree (key, COALESCE(label, ''::character varying)); \ No newline at end of file diff --git a/Tests/UnitTest1.cs b/Tests/UnitTest1.cs index d1492dc..fb9829e 100644 --- a/Tests/UnitTest1.cs +++ b/Tests/UnitTest1.cs @@ -35,8 +35,8 @@ namespace Tests { var conn = Container.Resolve(); - var dbSetup = new Database.Identity.DbSetup(conn); - await dbSetup.CreateDatabase("swp"); + var dbSetup = new Database.Identity.DbInfrastructureSetup(conn); + await dbSetup.CreateDatabaseWithSchema("swp"); }