Refactoring SetupConsole with DBFactory

This commit is contained in:
Janus C. H. Knudsen 2025-02-21 23:34:06 +01:00
parent 8dd01d291d
commit 78d49a9829
20 changed files with 337 additions and 407 deletions

View file

@ -1,6 +1,3 @@
using Microsoft.ApplicationInsights.DataContracts;
using System.Text;
namespace PlanTempus.Core.Logging namespace PlanTempus.Core.Logging
{ {
public record SeqConfiguration(string IngestionEndpoint, string ApiKey, string Environment); public record SeqConfiguration(string IngestionEndpoint, string ApiKey, string Environment);

View file

@ -11,9 +11,9 @@ namespace PlanTempus.Core.ModuleRegistry
protected override void Load(ContainerBuilder builder) protected override void Load(ContainerBuilder builder)
{ {
builder.RegisterType<MessageChannel>() //builder.RegisterType<MessageChannel>()
.As<IMessageChannel<Microsoft.ApplicationInsights.Channel.ITelemetry>>() // .As<IMessageChannel<Microsoft.ApplicationInsights.Channel.ITelemetry>>()
.SingleInstance(); // .SingleInstance();
builder.RegisterType<SeqBackgroundService>() builder.RegisterType<SeqBackgroundService>()
.As<Microsoft.Extensions.Hosting.IHostedService>() .As<Microsoft.Extensions.Hosting.IHostedService>()

View file

@ -6,29 +6,30 @@ namespace PlanTempus.Core.ModuleRegistry
{ {
public class TelemetryModule : Module public class TelemetryModule : Module
{ {
public TelemetryConfig TelemetryConfig { get; set; } public required TelemetryConfig TelemetryConfig { get; set; }
protected override void Load(ContainerBuilder builder) protected override void Load(ContainerBuilder builder)
{ {
if (TelemetryConfig == null)
throw new Exceptions.ConfigurationException("TelemetryConfig is missing");
var configuration = TelemetryConfiguration.CreateDefault(); var configuration = TelemetryConfiguration.CreateDefault();
configuration.ConnectionString = TelemetryConfig.ConnectionString; configuration.ConnectionString = TelemetryConfig.ConnectionString;
configuration.TelemetryChannel.DeveloperMode = true; configuration.TelemetryChannel.DeveloperMode = true;
if (TelemetryConfig.UseSeqLoggingTelemetryChannel) if (TelemetryConfig.UseSeqLoggingTelemetryChannel)
configuration.TelemetryChannel = new Telemetry.SeqLoggingTelemetryChannel(); ; {
var messageChannel = new Telemetry.MessageChannel();
var r = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(configuration); builder.RegisterInstance(messageChannel)
r.Use(next => new Telemetry.Enrichers.EnrichWithMetaTelemetry(next)); .As<Telemetry.IMessageChannel<ITelemetry>>()
r.Build(); .SingleInstance();
//builder.RegisterInstance(configuration); configuration.TelemetryChannel = new Telemetry.SeqLoggingTelemetryChannel(messageChannel);
}
var telemetryProcessorChain = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(configuration);
telemetryProcessorChain.Use(next => new Telemetry.Enrichers.EnrichWithMetaTelemetry(next));
telemetryProcessorChain.Build();
//builder.RegisterType<Microsoft.ApplicationInsights.TelemetryClient>()
// .InstancePerLifetimeScope();
var client = new Microsoft.ApplicationInsights.TelemetryClient(configuration); var client = new Microsoft.ApplicationInsights.TelemetryClient(configuration);
client.Context.GlobalProperties["Application"] = GetType().Namespace.Split('.')[0]; client.Context.GlobalProperties["Application"] = GetType().Namespace.Split('.')[0];

View file

@ -1,50 +1,27 @@
using Microsoft.ApplicationInsights.Channel; using Microsoft.ApplicationInsights.Channel;
using System.Net.Http.Headers;
namespace PlanTempus.Core.Telemetry namespace PlanTempus.Core.Telemetry
{ {
public class SeqLoggingTelemetryChannel : InMemoryChannel, ITelemetryChannel public class SeqLoggingTelemetryChannel : InMemoryChannel, ITelemetryChannel
{ {
public ITelemetryChannel _defaultChannel; private readonly IMessageChannel<ITelemetry> _messageChannel;
static HttpClient _client = new HttpClient();
static SeqLoggingTelemetryChannel() public SeqLoggingTelemetryChannel(IMessageChannel<ITelemetry> messageChannel)
{
_client = new HttpClient()
{
BaseAddress = new Uri("http://localhost:5341"),
Timeout = TimeSpan.FromSeconds(30)
};
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public SeqLoggingTelemetryChannel()
{ {
_messageChannel = messageChannel;
} }
public new void Send(ITelemetry telemetry) public new void Send(ITelemetry telemetry)
{ {
//var l = new SeqLogger(_client, "", ""); var writeTask = _messageChannel.Writer.WriteAsync(telemetry).AsTask();
writeTask.ContinueWith(t =>
//l.LogToSeq( {
// "Bruger {UserId} loggede ind", if (t.Exception != null)
// "Debug", {
// new Dictionary<string, object> { { "UserId", "12345" }, { "Counter", "i++" } } throw t.Exception;
// ); }
}, TaskContinuationOptions.OnlyOnFaulted);
//if (telemetry is Microsoft.ApplicationInsights.DataContracts.TraceTelemetry trace)
//{
// var severity = trace.SeverityLevel;
// Console.WriteLine($"Trace severity: {severity}, Message: {trace.Message}");
//}
base.Send(telemetry); base.Send(telemetry);
var logEntry = $"{DateTime.UtcNow:u}|{telemetry.Context.Operation.Name}|{telemetry.Context.Operation.Id}";
//File.AppendAllText(_filePath, logEntry + Environment.NewLine);
} }
} }
} }

View file

@ -15,9 +15,9 @@ public class SetupConfiguration : IDbConfigure<SetupConfiguration.Command>
{ {
_connectionFactory = connectionFactory; _connectionFactory = connectionFactory;
} }
public void With(Command notInUse) public void With(Command notInUse, ConnectionStringParameters parameters = null)
{ {
using var conn = _connectionFactory.Create(); using var conn = parameters is null ? _connectionFactory.Create() : _connectionFactory.Create(parameters);
using var transaction = conn.OpenWithTransaction(); using var transaction = conn.OpenWithTransaction();
try try
{ {

View file

@ -1,8 +1,10 @@
namespace PlanTempus.Database.Core.ConnectionFactory namespace PlanTempus.Database.Core.ConnectionFactory
{ {
public record ConnectionStringParameters(string user, string pwd);
public interface IDbConnectionFactory public interface IDbConnectionFactory
{ {
System.Data.IDbConnection Create(); System.Data.IDbConnection Create();
System.Data.IDbConnection Create(string username, string password); System.Data.IDbConnection Create(ConnectionStringParameters connectionStringTemplateParameters);
} }
} }

View file

@ -29,13 +29,13 @@ namespace PlanTempus.Database.Core.ConnectionFactory
return _baseDataSource.CreateConnection(); return _baseDataSource.CreateConnection();
} }
public IDbConnection Create(string username, string password) public IDbConnection Create(ConnectionStringParameters param)
{ {
var connectionStringBuilder = new NpgsqlConnectionStringBuilder( var connectionStringBuilder = new NpgsqlConnectionStringBuilder(
_baseDataSource.ConnectionString) _baseDataSource.ConnectionString)
{ {
Username = username, Username = param.user,
Password = password Password = param.pwd
}; };
var tempDataSourceBuilder = new NpgsqlDataSourceBuilder( var tempDataSourceBuilder = new NpgsqlDataSourceBuilder(

View file

@ -5,7 +5,6 @@ using PlanTempus.Database.Core.ConnectionFactory;
namespace PlanTempus.Database.Core.DCL namespace PlanTempus.Database.Core.DCL
{ {
/// <summary> /// <summary>
/// Only a superadmin or similar can create Application Users /// Only a superadmin or similar can create Application Users
/// </summary> /// </summary>
@ -18,7 +17,6 @@ namespace PlanTempus.Database.Core.DCL
public required string Password { get; init; } public required string Password { get; init; }
} }
Command _command; Command _command;
private readonly IDbConnectionFactory _connectionFactory; private readonly IDbConnectionFactory _connectionFactory;
@ -27,14 +25,14 @@ namespace PlanTempus.Database.Core.DCL
_connectionFactory = connectionFactory; _connectionFactory = connectionFactory;
} }
public void With(Command command) public void With(Command command, ConnectionStringParameters parameters = null)
{ {
_command = command; _command = command;
if (!Validations.IsValidSchemaName(_command.Schema)) if (!Validations.IsValidSchemaName(_command.Schema))
throw new ArgumentException("Invalid schema name", _command.Schema); throw new ArgumentException("Invalid schema name", _command.Schema);
using var conn = _connectionFactory.Create(); using var conn = parameters is null ? _connectionFactory.Create() : _connectionFactory.Create(parameters);
using var transaction = conn.OpenWithTransaction(); using var transaction = conn.OpenWithTransaction();
try try
{ {
@ -49,7 +47,6 @@ namespace PlanTempus.Database.Core.DCL
transaction.Rollback(); transaction.Rollback();
throw new InvalidOperationException("Failed to SetupApplicationUser in Database", ex); throw new InvalidOperationException("Failed to SetupApplicationUser in Database", ex);
} }
} }
private void CreateSchema(IDbConnection db) private void CreateSchema(IDbConnection db)

View file

@ -29,14 +29,14 @@ namespace PlanTempus.Database.Core.DCL
} }
public void With(Command command) public void With(Command command, ConnectionStringParameters parameters = null)
{ {
_command = command; _command = command;
if (!Validations.IsValidSchemaName(_command.Schema)) if (!Validations.IsValidSchemaName(_command.Schema))
throw new ArgumentException("Invalid schema name", _command.Schema); throw new ArgumentException("Invalid schema name", _command.Schema);
using var conn = _connectionFactory.Create(); using var conn = parameters is null ? _connectionFactory.Create() : _connectionFactory.Create(parameters);
using var transaction = conn.OpenWithTransaction(); using var transaction = conn.OpenWithTransaction();
try try
{ {
@ -83,8 +83,7 @@ namespace PlanTempus.Database.Core.DCL
{ {
// Grant USAGE og alle CREATE rettigheder på schema niveau // Grant USAGE og alle CREATE rettigheder på schema niveau
//GRANT USAGE ON SCHEMA {_command.Schema} TO {_command.User}; //GRANT USAGE ON SCHEMA {_command.Schema} TO {_command.User};
var sql = $@" var sql = $@"GRANT CREATE ON SCHEMA {_command.Schema} TO {_command.User};";
GRANT CREATE ON SCHEMA {_command.Schema} TO {_command.User};";
db.ExecuteSql(sql); db.ExecuteSql(sql);

View file

@ -2,6 +2,7 @@
using Insight.Database; using Insight.Database;
using PlanTempus.Database.Common; using PlanTempus.Database.Common;
using PlanTempus.Database.Core; using PlanTempus.Database.Core;
using PlanTempus.Database.Core.ConnectionFactory;
namespace PlanTempus.Database.Core.DCL namespace PlanTempus.Database.Core.DCL
{ {
@ -14,30 +15,29 @@ namespace PlanTempus.Database.Core.DCL
public required string Password { get; init; } public required string Password { get; init; }
} }
IDbConnection _db;
Command _command; Command _command;
private readonly IDbConnectionFactory _connectionFactory;
public SetupOrganization(IDbConnection db)
public SetupOrganization(IDbConnectionFactory connectionFactory)
{ {
_db = db; _connectionFactory = connectionFactory;
} }
public void With(Command command) public void With(Command command, ConnectionStringParameters parameters = null)
{ {
_command = command; _command = command;
if (!Validations.IsValidSchemaName(_command.Schema)) if (!Validations.IsValidSchemaName(_command.Schema))
throw new ArgumentException("Invalid schema name", _command.Schema); throw new ArgumentException("Invalid schema name", _command.Schema);
using (var transaction = _db.BeginTransaction()) using var conn = parameters is null ? _connectionFactory.Create() : _connectionFactory.Create(parameters);
{ using var transaction = conn.OpenWithTransaction();
try try
{ {
CreateSchema(); CreateSchema(conn);
CreateRole(); CreateRole(conn);
GrantSchemaRights(); GrantSchemaRights(conn);
transaction.Commit(); transaction.Commit();
} }
@ -46,49 +46,44 @@ namespace PlanTempus.Database.Core.DCL
transaction.Rollback(); transaction.Rollback();
throw new InvalidOperationException("Failed to SetupOrganization in Database", ex); throw new InvalidOperationException("Failed to SetupOrganization in Database", ex);
} }
}
} }
private void ExecuteSql(string sql)
{
_db.ExecuteSql(sql);
}
private void CreateSchema() private void CreateSchema(IDbConnection db)
{ {
var sql = $"CREATE SCHEMA IF NOT EXISTS {_command.Schema}"; var sql = $"CREATE SCHEMA IF NOT EXISTS {_command.Schema}";
ExecuteSql(sql); db.ExecuteSql(sql);
} }
private void CreateRole() private void CreateRole(IDbConnection db)
{ {
var sql = $"CREATE ROLE {_command.User} LOGIN PASSWORD '{_command.Password}';"; var sql = $"CREATE ROLE {_command.User} LOGIN PASSWORD '{_command.Password}';";
ExecuteSql(sql); db.ExecuteSql(sql);
var sql1 = $"ALTER ROLE {_command.User} SET search_path='{_command.Schema}';"; var sql1 = $"ALTER ROLE {_command.User} SET search_path='{_command.Schema}';";
ExecuteSql(sql1); db.ExecuteSql(sql1);
} }
private void GrantSchemaRights() private void GrantSchemaRights(IDbConnection db)
{ {
var sql = $"GRANT USAGE ON SCHEMA {_command.Schema} TO {_command.User};"; var sql = $"GRANT USAGE ON SCHEMA {_command.Schema} TO {_command.User};";
ExecuteSql(sql); db.ExecuteSql(sql);
var sql1 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} " + var sql1 = $"ALTER DEFAULT PRIVILEGES IN SCHEMA {_command.Schema} " +
$"GRANT INSERT, SELECT, UPDATE PRIVILEGES ON TABLES TO {_command.User};"; $"GRANT INSERT, SELECT, UPDATE PRIVILEGES ON TABLES TO {_command.User};";
ExecuteSql(sql1); db.ExecuteSql(sql1);
var sql2 = $"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA {_command.Schema} TO {_command.User};"; var sql2 = $"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA {_command.Schema} TO {_command.User};";
ExecuteSql(sql2); db.ExecuteSql(sql2);
var sql3 = $"GRANT CREATE TABLE ON SCHEMA {_command.Schema} TO {_command.User};"; var sql3 = $"GRANT CREATE TABLE ON SCHEMA {_command.Schema} TO {_command.User};";
ExecuteSql(sql3); db.ExecuteSql(sql3);
} }
public void RevokeCreateTable() public void RevokeCreateTable(IDbConnection db)
{ {
var sql = $"REVOKE CREATE TABLE ON SCHEMA {_command.Schema} FROM {_command.User};"; var sql = $"REVOKE CREATE TABLE ON SCHEMA {_command.Schema} FROM {_command.User};";
ExecuteSql(sql); db.ExecuteSql(sql);
} }
} }
} }

View file

@ -27,11 +27,11 @@ namespace PlanTempus.Database.Core.DDL
/// Creates the system tables in the specified schema within a transaction. /// Creates the system tables in the specified schema within a transaction.
/// </summary> /// </summary>
/// <param name="schema">The schema name where the tables will be created.</param> /// <param name="schema">The schema name where the tables will be created.</param>
public void With(Command command) public void With(Command command, ConnectionStringParameters parameters = null)
{ {
_command = command; _command = command;
using var conn = _connectionFactory.Create(); using var conn = parameters is null ? _connectionFactory.Create() : _connectionFactory.Create(parameters);
using var transaction = conn.OpenWithTransaction(); using var transaction = conn.OpenWithTransaction();
try try
{ {

View file

@ -2,6 +2,6 @@
{ {
public interface IDbConfigure<T> public interface IDbConfigure<T>
{ {
void With(T command); void With(T command, ConnectionFactory.ConnectionStringParameters parameters = null);
} }
} }

View file

@ -6,8 +6,6 @@ using System.Data;
namespace PlanTempus.Database.Core.Sql namespace PlanTempus.Database.Core.Sql
{ {
public class DatabaseScope : IDisposable public class DatabaseScope : IDisposable
{ {
private readonly IDbConnection _connection; private readonly IDbConnection _connection;
@ -99,6 +97,4 @@ namespace PlanTempus.Database.Core.Sql
} }
} }
} }

View file

@ -12,42 +12,14 @@ namespace PlanTempus.Database.ModuleRegistry
{ {
Insight.Database.Providers.PostgreSQL.PostgreSQLInsightDbProvider.RegisterProvider(); Insight.Database.Providers.PostgreSQL.PostgreSQLInsightDbProvider.RegisterProvider();
builder.Register<Core.ConnectionFactory.IDbConnectionFactory>(c => builder.RegisterType<Core.ConnectionFactory.PostgresConnectionFactory>()
new Core.ConnectionFactory.PostgresConnectionFactory(ConnectionString)) .As<Core.ConnectionFactory.IDbConnectionFactory>()
.WithParameter(new TypedParameter(typeof(string), ConnectionString))
.SingleInstance(); .SingleInstance();
builder.RegisterType<Core.Sql.SqlOperations>() builder.RegisterType<Core.Sql.SqlOperations>()
.As<Core.Sql.IDatabaseOperations>(); .As<Core.Sql.IDatabaseOperations>();
} }
} }
public class PostgresConnectionFactory1 //: IDbConnectionFactory
{
private readonly string _baseConnectionString;
public PostgresConnectionFactory1(string connectionString)
{
_baseConnectionString = connectionString;
}
public IDbConnection Create()
{
return new NpgsqlConnection(_baseConnectionString);
}
public IDbConnection Create(string username, string password)
{
var builder = new NpgsqlConnectionStringBuilder(_baseConnectionString)
{
Username = username,
Password = password
};
return new NpgsqlConnection(builder.ToString());
}
}
} }

View file

@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Npgsql; using Npgsql;
using PlanTempus.Database.ConfigurationManagementSystem; using PlanTempus.Database.ConfigurationManagementSystem;
using PlanTempus.Database.Core.ConnectionFactory;
using PlanTempus.Database.Core.DCL; using PlanTempus.Database.Core.DCL;
using PlanTempus.Database.Core.DDL; using PlanTempus.Database.Core.DDL;
using System.Data; using System.Data;
@ -61,28 +62,27 @@ namespace PlanTempus.SetupInfrastructure
static ConsoleColor _backgroundColor = Console.BackgroundColor; static ConsoleColor _backgroundColor = Console.BackgroundColor;
static ConsoleColor _foregroundColor = Console.ForegroundColor; static ConsoleColor _foregroundColor = Console.ForegroundColor;
private readonly IDbConnectionFactory _connectionFactory;
private readonly SetupDbAdmin _setupDbAdmin; private readonly SetupDbAdmin _setupDbAdmin;
private readonly SetupIdentitySystem _setupIdentitySystem; private readonly SetupIdentitySystem _setupIdentitySystem;
private readonly SetupConfiguration _setupConfiguration; private readonly SetupConfiguration _setupConfiguration;
private readonly SetupApplicationUser _setupApplicationUser; private readonly SetupApplicationUser _setupApplicationUser;
public ConsoleService(SetupDbAdmin setupDbAdmin, SetupIdentitySystem setupIdentitySystem, SetupConfiguration setupConfiguration, SetupApplicationUser setupApplicationUser) public ConsoleService(IDbConnectionFactory connectionFactory, SetupDbAdmin setupDbAdmin, SetupIdentitySystem setupIdentitySystem, SetupConfiguration setupConfiguration, SetupApplicationUser setupApplicationUser)
{ {
_connectionFactory = connectionFactory;
_setupDbAdmin = setupDbAdmin; _setupDbAdmin = setupDbAdmin;
_setupIdentitySystem = setupIdentitySystem; _setupIdentitySystem = setupIdentitySystem;
_setupConfiguration = setupConfiguration; _setupConfiguration = setupConfiguration;
_setupApplicationUser = setupApplicationUser; _setupApplicationUser = setupApplicationUser;
} }
static bool IsSuperAdmin() bool IsSuperAdmin(ConnectionStringParameters parameters)
{ {
//test db access
Console.WriteLine("Testing db access..."); Console.WriteLine("Testing db access...");
string query = @"SELECT usename, usesuper FROM pg_user WHERE usename = CURRENT_USER;"; string query = @"SELECT usename, usesuper FROM pg_user WHERE usename = CURRENT_USER;";
var conn = new NpgsqlConnection(); using var conn = _connectionFactory.Create(parameters);
var result = (dynamic)conn.QuerySql(query).Single(); var result = (dynamic)conn.QuerySql(query).Single();
string username = result.usename; string username = result.usename;
@ -91,12 +91,12 @@ namespace PlanTempus.SetupInfrastructure
if ((bool)result.usesuper) if ((bool)result.usesuper)
{ {
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine();
Console.BackgroundColor = ConsoleColor.Yellow; Console.BackgroundColor = ConsoleColor.Yellow;
Console.WriteLine();
Console.WriteLine("TEST SUCCESSFULLY"); Console.WriteLine("TEST SUCCESSFULLY");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = _backgroundColor; Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine();
Console.WriteLine("-------------------------------"); Console.WriteLine("-------------------------------");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine($"Username: {username}"); Console.WriteLine($"Username: {username}");
@ -118,7 +118,7 @@ namespace PlanTempus.SetupInfrastructure
Console.WriteLine("TEST WAS NOT SUCCESSFULLY"); Console.WriteLine("TEST WAS NOT SUCCESSFULLY");
Console.WriteLine(); Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = _backgroundColor; Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("-------------------------------"); Console.WriteLine("-------------------------------");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine($"Username: {username}"); Console.WriteLine($"Username: {username}");
@ -169,13 +169,12 @@ namespace PlanTempus.SetupInfrastructure
string.IsNullOrEmpty(userPass.Split(":")[0]) || string.IsNullOrEmpty(userPass.Split(":")[0]) ||
string.IsNullOrEmpty(userPass.Split(":")[1])); string.IsNullOrEmpty(userPass.Split(":")[1]));
//var ctp = new Startup.ConnectionStringTemplateParameters( var superUser = new ConnectionStringParameters(
// user: userPass.Split(":")[0], user: userPass.Split(":")[0],
// pwd: userPass.Split(":")[1] pwd: userPass.Split(":")[1]
//); );
//_container = new Startup().ConfigureContainer(ctp);
if (IsSuperAdmin()) if (IsSuperAdmin(superUser))
{ {
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
var sw = new Stopwatch(); var sw = new Stopwatch();
@ -183,26 +182,25 @@ namespace PlanTempus.SetupInfrastructure
Console.Write("Database.Core.DCL.SetupDbAdmin..."); Console.Write("Database.Core.DCL.SetupDbAdmin...");
sw.Start(); sw.Start();
_setupDbAdmin.With(new SetupDbAdmin.Command { Password = "3911", Schema = "system", User = "heimdall" }); _setupDbAdmin.With(new SetupDbAdmin.Command { Password = "3911", Schema = "system", User = "heimdall" }, superUser);
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms"); Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
Console.WriteLine("::"); Console.WriteLine("::");
Console.WriteLine("::"); Console.WriteLine("::");
Console.Write("Database.Core.DDL.SetupIdentitySystem..."); Console.Write("Database.Core.DDL.SetupIdentitySystem...");
sw.Restart(); sw.Restart();
//create new container with application user, we use that role from now. //use application user, we use that role from now.
//_container = new Startup().ConfigureContainer(new Startup.ConnectionStringTemplateParameters("heimdall", "3911")); var connParams = new ConnectionStringParameters(user: "heimdall", pwd: "3911");
_setupIdentitySystem.With(new SetupIdentitySystem.Command { Schema = "system" }); _setupIdentitySystem.With(new SetupIdentitySystem.Command { Schema = "system" }, connParams);
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms"); Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
Console.WriteLine("::"); Console.WriteLine("::");
Console.WriteLine("::"); Console.WriteLine("::");
Console.Write("Database.ConfigurationManagementSystem.SetupConfiguration..."); Console.Write("Database.ConfigurationManagementSystem.SetupConfiguration...");
sw.Restart(); sw.Restart();
_setupConfiguration.With(new SetupConfiguration.Command()); _setupConfiguration.With(new SetupConfiguration.Command(), connParams);
Console.Write($"DONE, took: {sw.ElapsedMilliseconds} ms"); Console.Write($"DONE, took: {sw.ElapsedMilliseconds} ms");
@ -211,7 +209,7 @@ namespace PlanTempus.SetupInfrastructure
Console.Write("Database.Core.DCL.SetupApplicationUser..."); Console.Write("Database.Core.DCL.SetupApplicationUser...");
sw.Start(); sw.Start();
_setupApplicationUser.With(new SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" }); _setupApplicationUser.With(new SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" }, superUser);
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms"); Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
@ -227,6 +225,7 @@ namespace PlanTempus.SetupInfrastructure
catch (Exception e) catch (Exception e)
{ {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine();
Console.WriteLine(e); Console.WriteLine(e);
} }

View file

@ -8,7 +8,6 @@ namespace PlanTempus.SetupInfrastructure
{ {
public class Startup public class Startup
{ {
public virtual IConfigurationRoot Configuration() public virtual IConfigurationRoot Configuration()
{ {
var configuration = new ConfigurationBuilder() var configuration = new ConfigurationBuilder()
@ -21,10 +20,8 @@ namespace PlanTempus.SetupInfrastructure
public void ConfigureContainer(ContainerBuilder builder) public void ConfigureContainer(ContainerBuilder builder)
{ {
//var builder = new ContainerBuilder();
var configuration = Configuration(); var configuration = Configuration();
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
{ {
ConnectionString = configuration.GetConnectionString("DefaultConnection") ConnectionString = configuration.GetConnectionString("DefaultConnection")
@ -47,9 +44,6 @@ namespace PlanTempus.SetupInfrastructure
builder.RegisterType<ConsoleService>(); builder.RegisterType<ConsoleService>();
}
//return builder.Build();
}
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id={usr};Password={pwd};" "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;"
}, },
"ApplicationInsights": { "ApplicationInsights": {
"ConnectionString": "InstrumentationKey=07d2a2b9-5e8e-4924-836e-264f8438f6c5;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=56748c39-2fa3-4880-a1e2-24068e791548", "ConnectionString": "InstrumentationKey=07d2a2b9-5e8e-4924-836e-264f8438f6c5;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=56748c39-2fa3-4880-a1e2-24068e791548",

View file

@ -1 +1 @@
{"resources":{"Scripts/Script-1.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"},"Scripts/Script.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44"},"Scripts/SmartConfigSystem.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"},"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"}}} {"resources":{"Scripts/Script-1.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"},"Scripts/Script.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"},"Scripts/SmartConfigSystem.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"},"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"}}}

View file

@ -36,5 +36,6 @@ SHOW search_path;
create table system.foos(id int) create table system.foos(id int)
select * from system.foo select * from system.foo
select * from "system".organizations

View file

@ -132,7 +132,7 @@ namespace PlanTempus.Tests.ConfigurationTests
} }
} }
public class Feature internal class Feature
{ {
public bool Enabled { get; set; } public bool Enabled { get; set; }
public int RolloutPercentage { get; set; } public int RolloutPercentage { get; set; }