Enhancing telemetry in Seq and fixes namespaces

This commit is contained in:
Janus C. H. Knudsen 2025-02-20 00:23:13 +01:00
parent 5568007237
commit 9f4996bc8f
65 changed files with 1122 additions and 1139 deletions

View file

@ -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);
}
}