modify production configs to use environment var for db connection

This commit is contained in:
Alan Moon 2025-03-19 12:06:27 -07:00
parent 9804c6c1a0
commit 51ead169e8
3 changed files with 3 additions and 7 deletions

View File

@ -12,7 +12,6 @@ public class ApiServerConfig {
public DbProviders ProdDbProvider { get; set; } = DbProviders.MySQL; public DbProviders ProdDbProvider { get; set; } = DbProviders.MySQL;
public string DbPath { get; set; } = string.Empty; public string DbPath { get; set; } = string.Empty;
public string DbConnection { get; set; } = string.Empty; public string DbConnection { get; set; } = string.Empty;
public string ProdDbConnection { get; set; } = string.Empty;
} }
public enum DbProviders { public enum DbProviders {

View File

@ -17,14 +17,14 @@ namespace sodoff.Model
#if USE_POSTGRESQL #if USE_POSTGRESQL
if (config.Value.ProdDbProvider == DbProviders.PostgreSQL) if (config.Value.ProdDbProvider == DbProviders.PostgreSQL)
{ {
optionsBuilder.UseNpgsql(config.Value.ProdDbConnection).UseLazyLoadingProxies(); optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("PRODUCTION_DB_CONNECTION")).UseLazyLoadingProxies();
return; return;
} }
#endif #endif
#if USE_MYSQL #if USE_MYSQL
if (config.Value.ProdDbProvider == DbProviders.MySQL) if (config.Value.ProdDbProvider == DbProviders.MySQL)
{ {
optionsBuilder.UseMySQL(config.Value.ProdDbConnection).UseLazyLoadingProxies(); optionsBuilder.UseMySQL(Environment.GetEnvironmentVariable("PRODUCTION_DB_CONNECTION")).UseLazyLoadingProxies();
return; return;
} }
#endif #endif

View File

@ -72,10 +72,7 @@
"// DbConnection": "Database connection string for PostgreSQL and MySQL", "// DbConnection": "Database connection string for PostgreSQL and MySQL",
"// DbConnection PostgreSQL Example": "Host=127.0.0.1;Database=sodoffdb;Username=sodoffuser;Password=secret", "// DbConnection PostgreSQL Example": "Host=127.0.0.1;Database=sodoffdb;Username=sodoffuser;Password=secret",
"// DbConnection MySQL Example": "Server=127.0.0.1;Database=sodoffdb;Uid=sodoffuser;Pwd=secret;Allow User Variables=True", "// DbConnection MySQL Example": "Server=127.0.0.1;Database=sodoffdb;Uid=sodoffuser;Pwd=secret;Allow User Variables=True",
"DbConnection": "", "DbConnection": ""
"// ProdDbConnection": "Database connection string for PostgreSQL and MySQL (examples above)",
"ProdDbConnection": "Server=${PRODUCTION_DB_SERVER};Database=sodoffdb;Uid=sodoffuser;Pwd=${PRODUCTION_DB_PASSWORD};Allow User Variables=True"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {