diff --git a/.deploy.yml b/.deploy.yml index 39e3233..fd2df00 100644 --- a/.deploy.yml +++ b/.deploy.yml @@ -32,6 +32,7 @@ GEEKBOT_DB_TRUST_CERT: "true" GEEKBOT_SUMOLOCIG: "{{ lookup('env', 'GEEKBOT_SUMOLOCIG') }}" GEEKBOT_SENTRY: "{{ lookup('env', 'GEEKBOT_SENTRY') }}" + GEEKBOT_DB_REDSHIFT_COMPAT: "true" - name: Cleanup Old Container docker_prune: images: yes diff --git a/Geekbot.net/Database/DatabaseInitializer.cs b/Geekbot.net/Database/DatabaseInitializer.cs index 637e7b8..9f60d8a 100644 --- a/Geekbot.net/Database/DatabaseInitializer.cs +++ b/Geekbot.net/Database/DatabaseInitializer.cs @@ -37,7 +37,8 @@ namespace Geekbot.net.Database Username = _runParameters.DbUser, Password = _runParameters.DbPassword, RequireSsl = _runParameters.DbSsl, - TrustServerCertificate = _runParameters.DbTrustCert + TrustServerCertificate = _runParameters.DbTrustCert, + RedshiftCompatibility = _runParameters.DbRedshiftCompatibility }); } } diff --git a/Geekbot.net/Database/SqlConnectionString.cs b/Geekbot.net/Database/SqlConnectionString.cs index 70346eb..61804cf 100644 --- a/Geekbot.net/Database/SqlConnectionString.cs +++ b/Geekbot.net/Database/SqlConnectionString.cs @@ -1,4 +1,6 @@ -namespace Geekbot.net.Database +using System.Text; + +namespace Geekbot.net.Database { public class SqlConnectionString { @@ -9,11 +11,29 @@ public string Password { get; set; } public bool RequireSsl { get; set; } public bool TrustServerCertificate { get; set; } + public bool RedshiftCompatibility { get; set; } public override string ToString() { + var sb = new StringBuilder(); + sb.Append("Application Name=Geekbot;"); + + sb.Append($"Host={Host};"); + sb.Append($"Port={Port};"); + sb.Append($"Database={Database};"); + sb.Append($"Username={Username};"); + sb.Append($"Password={Password};"); + var sslMode = RequireSsl ? "Require" : "Prefer"; - return $"ApplicationName=Geekbot;Server={Host};Port={Port};Database={Database};Uid={Username};Pwd={Password};SSLMode={sslMode};TrustServerCertificate={TrustServerCertificate.ToString()};"; + sb.Append($"SSL Mode={sslMode};"); + sb.Append($"Trust Server Certificate={TrustServerCertificate.ToString()};"); + + if (RedshiftCompatibility) + { + sb.Append("Server Compatibility Mode=Redshift"); + } + + return sb.ToString(); } } } \ No newline at end of file diff --git a/Geekbot.net/Lib/RunParameters.cs b/Geekbot.net/Lib/RunParameters.cs index bd8ce25..eb8c078 100644 --- a/Geekbot.net/Lib/RunParameters.cs +++ b/Geekbot.net/Lib/RunParameters.cs @@ -49,6 +49,9 @@ namespace Geekbot.net.Lib [Option("db-trust-cert", HelpText = "Trust the database certificate, regardless if it is valid (default: false) (env: DB_TRUST_CERT)")] public bool DbTrustCert { get; set; } = ParamFallback("DB_TRUST_CERT", false); + + [Option("db-redshift-compat", HelpText = "Enable compatibility for AWS Redshift and DigitalOcean Managed Database (default: false) (env: DB_REDSHIFT_COMPAT)")] + public bool DbRedshiftCompatibility { get; set; } = ParamFallback("DB_REDSHIFT_COMPAT", false); // Logging [Option("db-logging", HelpText = "Enable database logging (default: false) (env: DB_LOGGING)")]