From 6a555652fb68b3759bc66b782b576a7d92f75a9d Mon Sep 17 00:00:00 2001 From: code liturgy Date: Sun, 13 Nov 2022 16:53:18 +0000 Subject: [PATCH] Use PostgreSQL --- CodeLiturgy.Domain/CodeLiturgy.Domain.csproj | 1 + CodeLiturgy.Views/StartupExtensions.cs | 57 ++++---------------- CodeLiturgy.Views/appsettings.json | 4 +- 3 files changed, 12 insertions(+), 50 deletions(-) diff --git a/CodeLiturgy.Domain/CodeLiturgy.Domain.csproj b/CodeLiturgy.Domain/CodeLiturgy.Domain.csproj index 61feea5..603775b 100644 --- a/CodeLiturgy.Domain/CodeLiturgy.Domain.csproj +++ b/CodeLiturgy.Domain/CodeLiturgy.Domain.csproj @@ -27,6 +27,7 @@ + diff --git a/CodeLiturgy.Views/StartupExtensions.cs b/CodeLiturgy.Views/StartupExtensions.cs index 2e9e522..f01d9ed 100644 --- a/CodeLiturgy.Views/StartupExtensions.cs +++ b/CodeLiturgy.Views/StartupExtensions.cs @@ -9,6 +9,7 @@ using CodeLiturgy.Views.Utils; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; namespace CodeLiturgy.Views; @@ -147,50 +148,12 @@ public static class StartupExtensions } - /// - /// Get MYSQL Connection String - /// - /// - /// - /// - /* - private static DbContextOptionsBuilder GetMySqlSettings( - this DbContextOptionsBuilder optionsBuilder, - IConfiguration configuration, - IWebHostEnvironment environment) + private static DbContextOptionsBuilder UsePsqlConfiguration(this DbContextOptionsBuilder builder, IConfiguration configuration) { - var sqlVersion = GetMySqlServerVersion(8, 0, 11); - - // Docker / No-Docker - - - var mySqlConnectionString = configuration.GetConnectionString("MySQL"); - - if (mySqlConnectionString == string.Empty) - { - throw new InvalidOperationException("MySQL Connection string appears to be empty."); - } - - optionsBuilder - .UseMySql( - mySqlConnectionString, - sqlVersion) - .UseMySql(sqlVersion, - builder => { builder.EnableRetryOnFailure(6, TimeSpan.FromSeconds(3), null); }); - - // The following three options help with debugging, but should - // be changed or removed for production. - if (environment.IsDevelopment()) - { - optionsBuilder - .LogTo(Console.WriteLine, LogLevel.Information) - .EnableSensitiveDataLogging() - .EnableDetailedErrors(); - } - - return optionsBuilder; + var connString = configuration.GetConnectionString("database"); + builder.UseNpgsql(connString); + return builder; } - */ /// @@ -203,13 +166,11 @@ public static class StartupExtensions public static IServiceCollection PreparePostgresqlDatabasePool(this IServiceCollection serviceCollection, IConfiguration configuration, IWebHostEnvironment environment) { - return serviceCollection; - /*.AddDbContextPool(options => - options.GetMySqlSettings(configuration, environment)) - .AddDbContextPool(options => - options.GetMySqlSettings(configuration, environment)) + return serviceCollection + .AddDbContextPool(options => options.UsePsqlConfiguration(configuration)) + .AddDbContextPool(options => options.UsePsqlConfiguration(configuration)) .AddDbContextPool(options => - options.GetMySqlSettings(configuration, environment));*/ + options.UsePsqlConfiguration(configuration)); } diff --git a/CodeLiturgy.Views/appsettings.json b/CodeLiturgy.Views/appsettings.json index 65cc49f..9987243 100644 --- a/CodeLiturgy.Views/appsettings.json +++ b/CodeLiturgy.Views/appsettings.json @@ -8,10 +8,10 @@ "mode": "no-docker", "AllowedHosts": "*", "ConnectionStringDocker": { - "MySQL": "server=db;user=blueuser;password=dXjw127124dJ;database=bluedb;" + "database": "Server=127.0.0.1;User Id=clbdlocal;Password=C79J#MV))!YAiy/SzkCf;Database=cldblocal;" }, "ConnectionStringNoDocker": { - "MySQL": "server=localhost;user=blueuser;password=dXjw127124dJ;database=bluedb;" + "database": "Server=127.0.0.1;User Id=clbdlocal;Password=C79J#MV))!YAiy/SzkCf;Database=cldblocal;" }, "AuthSettings": { "SecretKey": "iJWHDmHLpUA283sqsfhqGbMRdRj1PVkH"