Use PostgreSQL

This commit is contained in:
code liturgy 2022-11-13 16:53:18 +00:00
parent f0caf1dbc4
commit 6a555652fb
3 changed files with 12 additions and 50 deletions

View File

@ -27,6 +27,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageReference Include="Npgsql" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

View File

@ -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
}
/// <summary>
/// Get MYSQL Connection String
/// </summary>
/// <param name="optionsBuilder"></param>
/// <param name="configuration"></param>
/// <param name="environment"></param>
/*
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;
}
*/
/// <summary>
@ -203,13 +166,11 @@ public static class StartupExtensions
public static IServiceCollection PreparePostgresqlDatabasePool(this IServiceCollection serviceCollection,
IConfiguration configuration, IWebHostEnvironment environment)
{
return serviceCollection;
/*.AddDbContextPool<UserDbContext>(options =>
options.GetMySqlSettings(configuration, environment))
.AddDbContextPool<CountryDbContext>(options =>
options.GetMySqlSettings(configuration, environment))
return serviceCollection
.AddDbContextPool<UserDbContext>(options => options.UsePsqlConfiguration(configuration))
.AddDbContextPool<CountryDbContext>(options => options.UsePsqlConfiguration(configuration))
.AddDbContextPool<ApplicationUserDbContext>(options =>
options.GetMySqlSettings(configuration, environment));*/
options.UsePsqlConfiguration(configuration));
}

View File

@ -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"