Fixes unable to create new DB when it doesnt exists.
This commit is contained in:
@@ -101,8 +101,8 @@ namespace Framework.Database
|
||||
// Create temporary query to use external MySQL CLi
|
||||
try
|
||||
{
|
||||
using BinaryWriter binaryWriter = new(File.Open(temp, FileMode.Create, FileAccess.Write));
|
||||
binaryWriter.Write($"CREATE DATABASE `{connectionObject.Database}` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
||||
using StreamWriter streamWriter = new(File.Open(temp, FileMode.Create, FileAccess.Write));
|
||||
streamWriter.Write($"CREATE DATABASE `{connectionObject.Database}` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -131,6 +131,9 @@ namespace Framework.Database
|
||||
if (_updateFlags == 0)
|
||||
Log.outInfo(LogFilter.SqlUpdates, "Automatic database updates are disabled for all databases!");
|
||||
|
||||
if (_updateFlags != 0 && !DBExecutableUtil.CheckExecutable())
|
||||
return false;
|
||||
|
||||
if (!OpenDatabases())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@ namespace Framework.Database
|
||||
if (!result.IsEmpty() && !result.IsEmpty())
|
||||
return true;
|
||||
|
||||
if (!DBUpdaterUtil.CheckExecutable())
|
||||
return false;
|
||||
|
||||
Log.outInfo(LogFilter.SqlUpdates, $"Database {_database.GetDatabaseName()} is empty, auto populating it...");
|
||||
|
||||
string path = GetSourceDirectory();
|
||||
@@ -71,9 +68,6 @@ namespace Framework.Database
|
||||
|
||||
public bool Update()
|
||||
{
|
||||
if (!DBUpdaterUtil.CheckExecutable())
|
||||
return false;
|
||||
|
||||
Log.outInfo(LogFilter.SqlUpdates, $"Updating {_database.GetDatabaseName()} database...");
|
||||
|
||||
string sourceDirectory = GetSourceDirectory();
|
||||
@@ -465,28 +459,4 @@ namespace Framework.Database
|
||||
Apply,
|
||||
Rehash
|
||||
}
|
||||
|
||||
static class DBUpdaterUtil
|
||||
{
|
||||
static string mysqlExecutablePath;
|
||||
|
||||
public static string GetMySQLExecutable()
|
||||
{
|
||||
return mysqlExecutablePath;
|
||||
}
|
||||
|
||||
public static bool CheckExecutable()
|
||||
{
|
||||
string mysqlExePath = ConfigMgr.GetDefaultValue("MySQLExecutable", "");
|
||||
if (mysqlExePath.IsEmpty() || !File.Exists(mysqlExePath))
|
||||
{
|
||||
Log.outFatal(LogFilter.SqlUpdates, $"Didn't find any executable MySQL binary at \'{mysqlExePath}\' or in path, correct the path in the *.conf (\"MySQLExecutable\").");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Correct the path to the cli
|
||||
mysqlExecutablePath = mysqlExePath;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
|
||||
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Framework.Configuration;
|
||||
using Framework.Threading;
|
||||
using MySqlConnector;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
@@ -286,7 +288,7 @@ namespace Framework.Database
|
||||
|
||||
// Invokes a mysql process which doesn't leak credentials to logs
|
||||
Process process = new();
|
||||
process.StartInfo = new(DBUpdaterUtil.GetMySQLExecutable());
|
||||
process.StartInfo = new(DBExecutableUtil.GetMySQLExecutable());
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
@@ -294,9 +296,11 @@ namespace Framework.Database
|
||||
process.StartInfo.Arguments = args;
|
||||
|
||||
process.Start();
|
||||
|
||||
process.WaitForExit();
|
||||
|
||||
Log.outInfo(LogFilter.SqlUpdates, process.StandardOutput.ReadToEnd());
|
||||
Log.outError(LogFilter.SqlUpdates, process.StandardError.ReadToEnd());
|
||||
process.WaitForExit();
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
@@ -421,4 +425,28 @@ namespace Framework.Database
|
||||
|
||||
public abstract void PreparedStatements();
|
||||
}
|
||||
|
||||
public static class DBExecutableUtil
|
||||
{
|
||||
static string mysqlExecutablePath;
|
||||
|
||||
public static string GetMySQLExecutable()
|
||||
{
|
||||
return mysqlExecutablePath;
|
||||
}
|
||||
|
||||
public static bool CheckExecutable()
|
||||
{
|
||||
string mysqlExePath = ConfigMgr.GetDefaultValue("MySQLExecutable", "");
|
||||
if (mysqlExePath.IsEmpty() || !File.Exists(mysqlExePath))
|
||||
{
|
||||
Log.outFatal(LogFilter.SqlUpdates, $"Didn't find any executable MySQL binary at \'{mysqlExePath}\' or in path, correct the path in the *.conf (\"MySQLExecutable\").");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Correct the path to the cli
|
||||
mysqlExecutablePath = mysqlExePath;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user