Skip to content

Commit

Permalink
Merge pull request #12 from peppy/custom-conn-string
Browse files Browse the repository at this point in the history
Add ability to specify custom database connection string (or password/database)
  • Loading branch information
smoogipoo authored Jun 3, 2022
2 parents 0737dee + 7d4cd76 commit ce88f41
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions osu.Server.QueueProcessor/QueueProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,21 @@ public long GetQueueSize() =>
/// </summary>
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.
Expand Down

0 comments on commit ce88f41

Please sign in to comment.