From 7d4cd7695af06d960f785c185c0c7e9c7d4934db Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 3 Jun 2022 17:37:48 +0900 Subject: [PATCH] Add ability to specify custom database connection string (or password/database) --- osu.Server.QueueProcessor/QueueProcessor.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/osu.Server.QueueProcessor/QueueProcessor.cs b/osu.Server.QueueProcessor/QueueProcessor.cs index f8d9ceb..1385b7f 100644 --- a/osu.Server.QueueProcessor/QueueProcessor.cs +++ b/osu.Server.QueueProcessor/QueueProcessor.cs @@ -210,10 +210,21 @@ public long GetQueueSize() => /// public virtual MySqlConnection GetDatabaseConnection() { - string host = (Environment.GetEnvironmentVariable("DB_HOST") ?? "localhost"); - string user = (Environment.GetEnvironmentVariable("DB_USER") ?? "root"); + string connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING") ?? String.Empty; - var connection = new MySqlConnection($"Server={host};Database=osu;User ID={user};ConnectionTimeout=5;ConnectionReset=false;Pooling=true;"); + if (string.IsNullOrEmpty(connectionString)) + { + string host = (Environment.GetEnvironmentVariable("DB_HOST") ?? "localhost"); + string user = (Environment.GetEnvironmentVariable("DB_USER") ?? "root"); + string password = (Environment.GetEnvironmentVariable("DB_PASS") ?? string.Empty); + string name = (Environment.GetEnvironmentVariable("DB_NAME") ?? "osu"); + + string passwordString = string.IsNullOrEmpty(password) ? string.Empty : $"Password={password};"; + + connectionString = $"Server={host};Database={name};User ID={user};{passwordString}ConnectionTimeout=5;ConnectionReset=false;Pooling=true;"; + } + + var connection = new MySqlConnection(connectionString); connection.Open(); // TODO: remove this when we have set a saner time zone server-side.