Adding db infrastructure setup
This commit is contained in:
parent
7dae58ec1e
commit
58bf4bea00
11 changed files with 125 additions and 6 deletions
|
|
@ -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;
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
13
SetupInfrastructure/CreateRole.txt
Normal file
13
SetupInfrastructure/CreateRole.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
CREATE ROLE sathumper WITH
|
||||
CREATEROLE
|
||||
CREATEDB
|
||||
LOGIN
|
||||
PASSWORD '<yoursecretpassword>';
|
||||
|
||||
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;
|
||||
|
||||
22
SetupInfrastructure/Program.cs
Normal file
22
SetupInfrastructure/Program.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
namespace SetupInfrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// 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=<secret>;"
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
20
SetupInfrastructure/SetupInfrastructure.csproj
Normal file
20
SetupInfrastructure/SetupInfrastructure.csproj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Database\Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
9
SetupInfrastructure/appsettings.json
Normal file
9
SetupInfrastructure/appsettings.json
Normal file
|
|
@ -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/"
|
||||
}
|
||||
}
|
||||
1
SqlManagement/.dbeaver/.project-metadata.json.bak
Normal file
1
SqlManagement/.dbeaver/.project-metadata.json.bak
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"resources":{"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"}}}
|
||||
1
SqlManagement/.dbeaver/project-metadata.json
Normal file
1
SqlManagement/.dbeaver/project-metadata.json
Normal file
|
|
@ -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"}}}
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
|
||||
|
||||
|
||||
|
||||
GRANT USAGE, CREATE ON SCHEMA swp TO sathumper;
|
||||
|
||||
ALTER DEFAULT PRIVILEGES IN SCHEMA swp
|
||||
|
|
|
|||
45
SqlManagement/Scripts/grant-privileges.sql
Normal file
45
SqlManagement/Scripts/grant-privileges.sql
Normal file
|
|
@ -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));
|
||||
|
|
@ -35,8 +35,8 @@ namespace Tests
|
|||
{
|
||||
var conn = Container.Resolve<IDbConnection>();
|
||||
|
||||
var dbSetup = new Database.Identity.DbSetup(conn);
|
||||
await dbSetup.CreateDatabase("swp");
|
||||
var dbSetup = new Database.Identity.DbInfrastructureSetup(conn);
|
||||
await dbSetup.CreateDatabaseWithSchema("swp");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue