Enhancing telemetry in Seq and fixes namespaces
This commit is contained in:
parent
5568007237
commit
9f4996bc8f
65 changed files with 1122 additions and 1139 deletions
|
|
@ -1,6 +1,6 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Database.Common
|
||||
namespace PlanTempus.Database.Common
|
||||
{
|
||||
internal class Validations
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,53 +1,54 @@
|
|||
using Insight.Database;
|
||||
using PlanTempus.Database.Core;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.ConfigurationManagementSystem;
|
||||
namespace PlanTempus.Database.ConfigurationManagementSystem;
|
||||
|
||||
public class SetupConfiguration : Core.IDbConfigure<SetupConfiguration.Command>
|
||||
public class SetupConfiguration : IDbConfigure<SetupConfiguration.Command>
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
|
||||
}
|
||||
public class Command
|
||||
{
|
||||
|
||||
private readonly IDbConnection _db;
|
||||
}
|
||||
|
||||
public SetupConfiguration(IDbConnection connection)
|
||||
{
|
||||
_db = connection;
|
||||
}
|
||||
public void With(Command notInUse)
|
||||
{
|
||||
using (var transaction = _db.OpenWithTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateConfigurationTable();
|
||||
CreateHistoryTable();
|
||||
CreateConfigurationIndexes();
|
||||
CreateModifiedAtTrigger();
|
||||
CreateNotifyTrigger();
|
||||
CreateHistoryTrigger();
|
||||
private readonly IDbConnection _db;
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to SetupConfiguration in Database", ex);
|
||||
}
|
||||
}
|
||||
public SetupConfiguration(IDbConnection connection)
|
||||
{
|
||||
_db = connection;
|
||||
}
|
||||
public void With(Command notInUse)
|
||||
{
|
||||
using (var transaction = _db.OpenWithTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateConfigurationTable();
|
||||
CreateHistoryTable();
|
||||
CreateConfigurationIndexes();
|
||||
CreateModifiedAtTrigger();
|
||||
CreateNotifyTrigger();
|
||||
CreateHistoryTrigger();
|
||||
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to SetupConfiguration in Database", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteSql(string sql)
|
||||
{
|
||||
_db.ExecuteSql(sql);
|
||||
}
|
||||
}
|
||||
|
||||
void CreateConfigurationTable()
|
||||
{
|
||||
const string sql = @"
|
||||
private void ExecuteSql(string sql)
|
||||
{
|
||||
_db.ExecuteSql(sql);
|
||||
}
|
||||
|
||||
void CreateConfigurationTable()
|
||||
{
|
||||
const string sql = @"
|
||||
CREATE TABLE IF NOT EXISTS app_configuration (
|
||||
id bigserial NOT NULL,
|
||||
""key"" varchar(255) NOT NULL,
|
||||
|
|
@ -61,12 +62,12 @@ public class SetupConfiguration : Core.IDbConfigure<SetupConfiguration.Command>
|
|||
etag uuid DEFAULT gen_random_uuid() NULL,
|
||||
CONSTRAINT app_configuration_pkey PRIMARY KEY (id)
|
||||
);";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
void CreateHistoryTable()
|
||||
{
|
||||
const string sql = @"
|
||||
void CreateHistoryTable()
|
||||
{
|
||||
const string sql = @"
|
||||
CREATE TABLE IF NOT EXISTS app_configuration_history (
|
||||
history_id bigserial NOT NULL,
|
||||
action_type char(1) NOT NULL,
|
||||
|
|
@ -84,20 +85,20 @@ public class SetupConfiguration : Core.IDbConfigure<SetupConfiguration.Command>
|
|||
etag uuid NULL,
|
||||
CONSTRAINT app_configuration_history_pkey PRIMARY KEY (history_id)
|
||||
);";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
void CreateConfigurationIndexes()
|
||||
{
|
||||
const string sql = @"
|
||||
void CreateConfigurationIndexes()
|
||||
{
|
||||
const string sql = @"
|
||||
CREATE INDEX IF NOT EXISTS idx_app_configuration_key ON app_configuration(""key"");
|
||||
CREATE INDEX IF NOT EXISTS idx_app_configuration_validity ON app_configuration(valid_from, expires_at);";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
void CreateModifiedAtTrigger()
|
||||
{
|
||||
const string sql = @"
|
||||
void CreateModifiedAtTrigger()
|
||||
{
|
||||
const string sql = @"
|
||||
CREATE OR REPLACE FUNCTION update_app_configuration_modified_at()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
|
|
@ -110,12 +111,12 @@ public class SetupConfiguration : Core.IDbConfigure<SetupConfiguration.Command>
|
|||
BEFORE UPDATE ON app_configuration
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_app_configuration_modified_at();";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
void CreateNotifyTrigger()
|
||||
{
|
||||
const string sql = @"
|
||||
void CreateNotifyTrigger()
|
||||
{
|
||||
const string sql = @"
|
||||
CREATE OR REPLACE FUNCTION notify_app_configuration_change()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
|
|
@ -128,12 +129,12 @@ public class SetupConfiguration : Core.IDbConfigure<SetupConfiguration.Command>
|
|||
AFTER INSERT OR UPDATE ON app_configuration
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION notify_app_configuration_change();";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
void CreateHistoryTrigger()
|
||||
{
|
||||
const string sql = @"
|
||||
void CreateHistoryTrigger()
|
||||
{
|
||||
const string sql = @"
|
||||
CREATE OR REPLACE FUNCTION log_app_configuration_changes()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
|
|
@ -172,8 +173,8 @@ public class SetupConfiguration : Core.IDbConfigure<SetupConfiguration.Command>
|
|||
CREATE OR REPLACE TRIGGER trg_app_configuration_history
|
||||
AFTER INSERT OR UPDATE OR DELETE ON app_configuration
|
||||
FOR EACH ROW EXECUTE FUNCTION log_app_configuration_changes();";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,113 +1,114 @@
|
|||
using System.Data;
|
||||
using Database.Common;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Database.Common;
|
||||
using PlanTempus.Database.Core;
|
||||
|
||||
namespace Database.Core.DCL
|
||||
namespace PlanTempus.Database.Core.DCL
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Only a superadmin or similar can create Application Users
|
||||
/// </summary>
|
||||
public class SetupApplicationUser : IDbConfigure<SetupApplicationUser.Command>
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public required string Schema { get; init; }
|
||||
public required string User { get; init; }
|
||||
public required string Password { get; init; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Only a superadmin or similar can create Application Users
|
||||
/// </summary>
|
||||
public class SetupApplicationUser : IDbConfigure<SetupApplicationUser.Command>
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public required string Schema { get; init; }
|
||||
public required string User { get; init; }
|
||||
public required string Password { get; init; }
|
||||
}
|
||||
|
||||
|
||||
IDbConnection _db;
|
||||
Command _command;
|
||||
IDbConnection _db;
|
||||
Command _command;
|
||||
|
||||
public SetupApplicationUser(IDbConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public void With(Command command)
|
||||
{
|
||||
_command = command;
|
||||
public SetupApplicationUser(IDbConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
if (!Validations.IsValidSchemaName(_command.Schema))
|
||||
throw new ArgumentException("Invalid schema name", _command.Schema);
|
||||
public void With(Command command)
|
||||
{
|
||||
_command = command;
|
||||
|
||||
using (var transaction = _db.OpenWithTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateSchema();
|
||||
CreateRole();
|
||||
GrantSchemaRights();
|
||||
if (!Validations.IsValidSchemaName(_command.Schema))
|
||||
throw new ArgumentException("Invalid schema name", _command.Schema);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to SetupApplicationUser in Database", ex);
|
||||
}
|
||||
}
|
||||
using (var transaction = _db.OpenWithTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateSchema();
|
||||
CreateRole();
|
||||
GrantSchemaRights();
|
||||
|
||||
}
|
||||
private void ExecuteSql(string sql)
|
||||
{
|
||||
_db.ExecuteSql(sql);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to SetupApplicationUser in Database", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSchema()
|
||||
{
|
||||
var sql = $"CREATE SCHEMA IF NOT EXISTS {_command.Schema}";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
}
|
||||
private void ExecuteSql(string sql)
|
||||
{
|
||||
_db.ExecuteSql(sql);
|
||||
}
|
||||
|
||||
private void CreateRole()
|
||||
{
|
||||
var sql = $@"
|
||||
private void CreateSchema()
|
||||
{
|
||||
var sql = $"CREATE SCHEMA IF NOT EXISTS {_command.Schema}";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
private void CreateRole()
|
||||
{
|
||||
var sql = $@"
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '{_command.User}') THEN
|
||||
CREATE ROLE {_command.User} WITH CREATEDB CREATEROLE LOGIN PASSWORD '{_command.Password}';
|
||||
END IF;
|
||||
END $$;";
|
||||
ExecuteSql(sql);
|
||||
ExecuteSql(sql);
|
||||
|
||||
var sql1 = $"ALTER ROLE {_command.User} SET search_path='{_command.Schema}';";
|
||||
ExecuteSql(sql1);
|
||||
}
|
||||
var sql1 = $"ALTER ROLE {_command.User} SET search_path='{_command.Schema}';";
|
||||
ExecuteSql(sql1);
|
||||
}
|
||||
|
||||
private void GrantSchemaRights()
|
||||
{
|
||||
// Grant USAGE og alle CREATE rettigheder på schema niveau
|
||||
var sql = $@"
|
||||
private void GrantSchemaRights()
|
||||
{
|
||||
// Grant USAGE og alle CREATE rettigheder på schema niveau
|
||||
var sql = $@"
|
||||
GRANT USAGE ON SCHEMA {_command.Schema} TO {_command.User};
|
||||
GRANT ALL ON SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql);
|
||||
ExecuteSql(sql);
|
||||
|
||||
// Grant rettigheder på eksisterende og fremtidige tabeller
|
||||
var sql1 = $"GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql1);
|
||||
// Grant rettigheder på eksisterende og fremtidige tabeller
|
||||
var sql1 = $"GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql1);
|
||||
|
||||
var sql2 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT ALL PRIVILEGES ON TABLES TO {_command.User};";
|
||||
ExecuteSql(sql2);
|
||||
var sql2 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT ALL PRIVILEGES ON TABLES TO {_command.User};";
|
||||
ExecuteSql(sql2);
|
||||
|
||||
// Grant sequence rettigheder
|
||||
var sql3 = $"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql3);
|
||||
// Grant sequence rettigheder
|
||||
var sql3 = $"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql3);
|
||||
|
||||
// Grant execute på functions
|
||||
var sql4 = $"GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql4);
|
||||
// Grant execute på functions
|
||||
var sql4 = $"GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql4);
|
||||
|
||||
// Grant for fremtidige functions
|
||||
var sql5 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT EXECUTE ON FUNCTIONS TO {_command.User};";
|
||||
ExecuteSql(sql5);
|
||||
// Grant for fremtidige functions
|
||||
var sql5 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT EXECUTE ON FUNCTIONS TO {_command.User};";
|
||||
ExecuteSql(sql5);
|
||||
|
||||
// Grant for fremtidige sequences
|
||||
var sql6 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT USAGE ON SEQUENCES TO {_command.User};";
|
||||
ExecuteSql(sql6);
|
||||
}
|
||||
// Grant for fremtidige sequences
|
||||
var sql6 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} GRANT USAGE ON SEQUENCES TO {_command.User};";
|
||||
ExecuteSql(sql6);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
using System.Data;
|
||||
using Database.Common;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Database.Common;
|
||||
using PlanTempus.Database.Core;
|
||||
|
||||
namespace Database.Core.DCL
|
||||
namespace PlanTempus.Database.Core.DCL
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -76,7 +77,7 @@ namespace Database.Core.DCL
|
|||
|
||||
var sql1 = $"ALTER ROLE {_command.User} SET search_path='{_command.Schema}';";
|
||||
ExecuteSql(sql1);
|
||||
|
||||
|
||||
var sql2 = $"ALTER SCHEMA {_command.Schema} OWNER TO {_command.User};";
|
||||
ExecuteSql(sql2);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,93 +1,94 @@
|
|||
using System.Data;
|
||||
using Database.Common;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Database.Common;
|
||||
using PlanTempus.Database.Core;
|
||||
|
||||
namespace Database.Core.DCL
|
||||
namespace PlanTempus.Database.Core.DCL
|
||||
{
|
||||
public class SetupOrganization : IDbConfigure<SetupOrganization.Command>
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public required string Schema { get; init; }
|
||||
public required string User { get; init; }
|
||||
public required string Password { get; init; }
|
||||
}
|
||||
public class SetupOrganization : IDbConfigure<SetupOrganization.Command>
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public required string Schema { get; init; }
|
||||
public required string User { get; init; }
|
||||
public required string Password { get; init; }
|
||||
}
|
||||
|
||||
IDbConnection _db;
|
||||
Command _command;
|
||||
IDbConnection _db;
|
||||
Command _command;
|
||||
|
||||
public SetupOrganization(IDbConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
public SetupOrganization(IDbConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public void With(Command command)
|
||||
{
|
||||
public void With(Command command)
|
||||
{
|
||||
|
||||
_command = command;
|
||||
_command = command;
|
||||
|
||||
|
||||
if (!Validations.IsValidSchemaName(_command.Schema))
|
||||
throw new ArgumentException("Invalid schema name", _command.Schema);
|
||||
if (!Validations.IsValidSchemaName(_command.Schema))
|
||||
throw new ArgumentException("Invalid schema name", _command.Schema);
|
||||
|
||||
using (var transaction = _db.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateSchema();
|
||||
CreateRole();
|
||||
GrantSchemaRights();
|
||||
using (var transaction = _db.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateSchema();
|
||||
CreateRole();
|
||||
GrantSchemaRights();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to SetupOrganization in Database", ex);
|
||||
}
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to SetupOrganization in Database", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void ExecuteSql(string sql)
|
||||
{
|
||||
_db.ExecuteSql(sql);
|
||||
}
|
||||
}
|
||||
private void ExecuteSql(string sql)
|
||||
{
|
||||
_db.ExecuteSql(sql);
|
||||
}
|
||||
|
||||
private void CreateSchema()
|
||||
{
|
||||
var sql = $"CREATE SCHEMA IF NOT EXISTS {_command.Schema}";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
private void CreateSchema()
|
||||
{
|
||||
var sql = $"CREATE SCHEMA IF NOT EXISTS {_command.Schema}";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
private void CreateRole()
|
||||
{
|
||||
var sql = $"CREATE ROLE {_command.User} LOGIN PASSWORD '{_command.Password}';";
|
||||
ExecuteSql(sql);
|
||||
private void CreateRole()
|
||||
{
|
||||
var sql = $"CREATE ROLE {_command.User} LOGIN PASSWORD '{_command.Password}';";
|
||||
ExecuteSql(sql);
|
||||
|
||||
var sql1 = $"ALTER ROLE {_command.User} SET search_path='{_command.Schema}';";
|
||||
ExecuteSql(sql1);
|
||||
var sql1 = $"ALTER ROLE {_command.User} SET search_path='{_command.Schema}';";
|
||||
ExecuteSql(sql1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void GrantSchemaRights()
|
||||
{
|
||||
var sql = $"GRANT USAGE ON SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql);
|
||||
private void GrantSchemaRights()
|
||||
{
|
||||
var sql = $"GRANT USAGE ON SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql);
|
||||
|
||||
var sql1 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} " +
|
||||
$"GRANT INSERT, SELECT, UPDATE PRIVILEGES ON TABLES TO {_command.User};";
|
||||
ExecuteSql(sql1);
|
||||
var sql1 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} " +
|
||||
$"GRANT INSERT, SELECT, UPDATE PRIVILEGES ON TABLES TO {_command.User};";
|
||||
ExecuteSql(sql1);
|
||||
|
||||
var sql2 = $"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql2);
|
||||
var sql2 = $"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql2);
|
||||
|
||||
var sql3 = $"GRANT CREATE TABLE ON SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql3);
|
||||
}
|
||||
public void RevokeCreateTable()
|
||||
{
|
||||
var sql = $"REVOKE CREATE TABLE ON SCHEMA {_command.Schema} FROM {_command.User};";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
}
|
||||
var sql3 = $"GRANT CREATE TABLE ON SCHEMA {_command.Schema} TO {_command.User};";
|
||||
ExecuteSql(sql3);
|
||||
}
|
||||
public void RevokeCreateTable()
|
||||
{
|
||||
var sql = $"REVOKE CREATE TABLE ON SCHEMA {_command.Schema} FROM {_command.User};";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
using Insight.Database;
|
||||
using PlanTempus.Database.Core;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.Core.DDL
|
||||
namespace PlanTempus.Database.Core.DDL
|
||||
{
|
||||
/// <summary>
|
||||
/// This is by purpose not async await
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
namespace Database.Core
|
||||
namespace PlanTempus.Database.Core
|
||||
{
|
||||
public interface IDbConfigure<T>
|
||||
{
|
||||
void With(T command);
|
||||
}
|
||||
public interface IDbConfigure<T>
|
||||
{
|
||||
void With(T command);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
using Core.Entities.Users;
|
||||
using Insight.Database;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Core.Entities.Users;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.Core
|
||||
namespace PlanTempus.Database.Core
|
||||
{
|
||||
public class UserService
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
using Autofac;
|
||||
using Npgsql;
|
||||
using System.Data;
|
||||
namespace Database.ModuleRegistry
|
||||
namespace PlanTempus.Database.ModuleRegistry
|
||||
{
|
||||
public class DbPostgreSqlModule : Module
|
||||
{
|
||||
public required string ConnectionString { get; set; }
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
Insight.Database.Providers.PostgreSQL.PostgreSQLInsightDbProvider.RegisterProvider();
|
||||
public class DbPostgreSqlModule : Module
|
||||
{
|
||||
public required string ConnectionString { get; set; }
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
Insight.Database.Providers.PostgreSQL.PostgreSQLInsightDbProvider.RegisterProvider();
|
||||
|
||||
builder.Register(c =>
|
||||
{
|
||||
IDbConnection connection = new NpgsqlConnection(ConnectionString);
|
||||
return connection;
|
||||
})
|
||||
.InstancePerLifetimeScope();
|
||||
builder.Register(c =>
|
||||
{
|
||||
IDbConnection connection = new NpgsqlConnection(ConnectionString);
|
||||
return connection;
|
||||
})
|
||||
.InstancePerLifetimeScope();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
using Insight.Database;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.NavigationSystem
|
||||
namespace PlanTempus.Database.NavigationSystem
|
||||
{
|
||||
internal class Setup
|
||||
{
|
||||
internal class Setup
|
||||
{
|
||||
|
||||
private readonly IDbConnection _db;
|
||||
private readonly IDbConnection _db;
|
||||
|
||||
public Setup(IDbConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
public void CreateSystem()
|
||||
{
|
||||
//await CreateNavigationLinkTemplatesTable(schema);
|
||||
//await CreateNavigationLinkTemplateTranslationsTable(schema);
|
||||
}
|
||||
public Setup(IDbConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
public void CreateSystem()
|
||||
{
|
||||
//await CreateNavigationLinkTemplatesTable(schema);
|
||||
//await CreateNavigationLinkTemplateTranslationsTable(schema);
|
||||
}
|
||||
|
||||
private async Task CreateNavigationLinkTemplatesTable()
|
||||
{
|
||||
var sql = $@"
|
||||
private async Task CreateNavigationLinkTemplatesTable()
|
||||
{
|
||||
var sql = $@"
|
||||
CREATE TABLE IF NOT EXISTS navigation_link_templates (
|
||||
id SERIAL PRIMARY KEY,
|
||||
parent_id INTEGER NULL,
|
||||
|
|
@ -31,12 +31,12 @@ namespace Database.NavigationSystem
|
|||
FOREIGN KEY (permission_id) REFERENCES permissions(id),
|
||||
FOREIGN KEY (parent_id) REFERENCES navigation_link_templates(id)
|
||||
)";
|
||||
await _db.ExecuteAsync(sql);
|
||||
}
|
||||
await _db.ExecuteAsync(sql);
|
||||
}
|
||||
|
||||
private async Task CreateNavigationLinkTemplateTranslationsTable(string schema)
|
||||
{
|
||||
var sql = $@"
|
||||
private async Task CreateNavigationLinkTemplateTranslationsTable(string schema)
|
||||
{
|
||||
var sql = $@"
|
||||
CREATE TABLE IF NOT EXISTS navigation_link_template_translations (
|
||||
id SERIAL PRIMARY KEY,
|
||||
template_id INTEGER NOT NULL,
|
||||
|
|
@ -44,7 +44,7 @@ namespace Database.NavigationSystem
|
|||
display_name VARCHAR(100) NOT NULL,
|
||||
FOREIGN KEY (template_id) REFERENCES navigation_link_templates(id)
|
||||
)";
|
||||
await _db.ExecuteAsync(sql);
|
||||
}
|
||||
}
|
||||
await _db.ExecuteAsync(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
<ProjectReference Include="..\Core\PlanTempus.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -1,92 +1,91 @@
|
|||
using System.Data;
|
||||
using Database.Common;
|
||||
using Insight.Database;
|
||||
|
||||
namespace Database.RolesPermissionSystem
|
||||
namespace PlanTempus.Database.RolesPermissionSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// This is by purpose not async await
|
||||
/// It is intended that this is created with the correct Application User, which is why the schema name is omitted.
|
||||
/// </summary>
|
||||
public class Setup
|
||||
{
|
||||
IDbConnection _db;
|
||||
/// <summary>
|
||||
/// This is by purpose not async await
|
||||
/// It is intended that this is created with the correct Application User, which is why the schema name is omitted.
|
||||
/// </summary>
|
||||
public class Setup
|
||||
{
|
||||
IDbConnection _db;
|
||||
|
||||
public Setup(IDbConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
public Setup(IDbConnection db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the system tables in the specified schema within a transaction.
|
||||
/// </summary>
|
||||
/// <param name="schema">The schema name where the tables will be created.</param>
|
||||
public void CreateSystem()
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the system tables in the specified schema within a transaction.
|
||||
/// </summary>
|
||||
/// <param name="schema">The schema name where the tables will be created.</param>
|
||||
public void CreateSystem()
|
||||
{
|
||||
|
||||
//if (!Validations.IsValidSchemaName(_schema))
|
||||
// throw new ArgumentException("Invalid schema name", _schema);
|
||||
//if (!Validations.IsValidSchemaName(_schema))
|
||||
// throw new ArgumentException("Invalid schema name", _schema);
|
||||
|
||||
using (var transaction = _db.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateRolesTable();
|
||||
CreatePermissionsTable();
|
||||
CreatePermissionTypesTable();
|
||||
CreateRolePermissionsTable();
|
||||
using (var transaction = _db.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateRolesTable();
|
||||
CreatePermissionsTable();
|
||||
CreatePermissionTypesTable();
|
||||
CreateRolePermissionsTable();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to create system tables.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to create system tables.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ExecuteSql(string sql)
|
||||
{
|
||||
_db.ExecuteSql(sql);
|
||||
}
|
||||
private void ExecuteSql(string sql)
|
||||
{
|
||||
_db.ExecuteSql(sql);
|
||||
}
|
||||
|
||||
private void CreatePermissionTypesTable()
|
||||
{
|
||||
var sql = $@"
|
||||
private void CreatePermissionTypesTable()
|
||||
{
|
||||
var sql = $@"
|
||||
CREATE TABLE IF NOT EXISTS permission_types (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL UNIQUE
|
||||
)";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
private void CreatePermissionsTable()
|
||||
{
|
||||
var sql = $@"
|
||||
private void CreatePermissionsTable()
|
||||
{
|
||||
var sql = $@"
|
||||
CREATE TABLE IF NOT EXISTS permissions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL UNIQUE,
|
||||
type_id INTEGER NOT NULL,
|
||||
FOREIGN KEY (type_id) REFERENCES permission_types(id)
|
||||
)";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
private void CreateRolesTable()
|
||||
{
|
||||
var sql = $@"
|
||||
private void CreateRolesTable()
|
||||
{
|
||||
var sql = $@"
|
||||
CREATE TABLE IF NOT EXISTS roles (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL UNIQUE
|
||||
)";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
|
||||
private void CreateRolePermissionsTable()
|
||||
{
|
||||
var sql = $@"
|
||||
private void CreateRolePermissionsTable()
|
||||
{
|
||||
var sql = $@"
|
||||
CREATE TABLE IF NOT EXISTS role_permissions (
|
||||
role_id INTEGER NOT NULL,
|
||||
permission_id INTEGER NOT NULL,
|
||||
|
|
@ -94,7 +93,7 @@ namespace Database.RolesPermissionSystem
|
|||
FOREIGN KEY (role_id) REFERENCES roles(id),
|
||||
FOREIGN KEY (permission_id) REFERENCES permissions(id)
|
||||
)";
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
}
|
||||
ExecuteSql(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using Insight.Database;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.Tenants
|
||||
namespace PlanTempus.Database.Tenants
|
||||
{
|
||||
internal class InitializeOrganizationData
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue