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
|
// Create temporary query to use external MySQL CLi
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using BinaryWriter binaryWriter = new(File.Open(temp, FileMode.Create, FileAccess.Write));
|
using StreamWriter streamWriter = new(File.Open(temp, FileMode.Create, FileAccess.Write));
|
||||||
binaryWriter.Write($"CREATE DATABASE `{connectionObject.Database}` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
streamWriter.Write($"CREATE DATABASE `{connectionObject.Database}` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -131,6 +131,9 @@ namespace Framework.Database
|
|||||||
if (_updateFlags == 0)
|
if (_updateFlags == 0)
|
||||||
Log.outInfo(LogFilter.SqlUpdates, "Automatic database updates are disabled for all databases!");
|
Log.outInfo(LogFilter.SqlUpdates, "Automatic database updates are disabled for all databases!");
|
||||||
|
|
||||||
|
if (_updateFlags != 0 && !DBExecutableUtil.CheckExecutable())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!OpenDatabases())
|
if (!OpenDatabases())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ namespace Framework.Database
|
|||||||
if (!result.IsEmpty() && !result.IsEmpty())
|
if (!result.IsEmpty() && !result.IsEmpty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!DBUpdaterUtil.CheckExecutable())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Log.outInfo(LogFilter.SqlUpdates, $"Database {_database.GetDatabaseName()} is empty, auto populating it...");
|
Log.outInfo(LogFilter.SqlUpdates, $"Database {_database.GetDatabaseName()} is empty, auto populating it...");
|
||||||
|
|
||||||
string path = GetSourceDirectory();
|
string path = GetSourceDirectory();
|
||||||
@@ -71,9 +68,6 @@ namespace Framework.Database
|
|||||||
|
|
||||||
public bool Update()
|
public bool Update()
|
||||||
{
|
{
|
||||||
if (!DBUpdaterUtil.CheckExecutable())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Log.outInfo(LogFilter.SqlUpdates, $"Updating {_database.GetDatabaseName()} database...");
|
Log.outInfo(LogFilter.SqlUpdates, $"Updating {_database.GetDatabaseName()} database...");
|
||||||
|
|
||||||
string sourceDirectory = GetSourceDirectory();
|
string sourceDirectory = GetSourceDirectory();
|
||||||
@@ -465,28 +459,4 @@ namespace Framework.Database
|
|||||||
Apply,
|
Apply,
|
||||||
Rehash
|
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.
|
// 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.
|
// 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 Framework.Threading;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
@@ -286,7 +288,7 @@ namespace Framework.Database
|
|||||||
|
|
||||||
// Invokes a mysql process which doesn't leak credentials to logs
|
// Invokes a mysql process which doesn't leak credentials to logs
|
||||||
Process process = new();
|
Process process = new();
|
||||||
process.StartInfo = new(DBUpdaterUtil.GetMySQLExecutable());
|
process.StartInfo = new(DBExecutableUtil.GetMySQLExecutable());
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
process.StartInfo.RedirectStandardError = true;
|
process.StartInfo.RedirectStandardError = true;
|
||||||
@@ -294,9 +296,11 @@ namespace Framework.Database
|
|||||||
process.StartInfo.Arguments = args;
|
process.StartInfo.Arguments = args;
|
||||||
|
|
||||||
process.Start();
|
process.Start();
|
||||||
|
|
||||||
|
process.WaitForExit();
|
||||||
|
|
||||||
Log.outInfo(LogFilter.SqlUpdates, process.StandardOutput.ReadToEnd());
|
Log.outInfo(LogFilter.SqlUpdates, process.StandardOutput.ReadToEnd());
|
||||||
Log.outError(LogFilter.SqlUpdates, process.StandardError.ReadToEnd());
|
Log.outError(LogFilter.SqlUpdates, process.StandardError.ReadToEnd());
|
||||||
process.WaitForExit();
|
|
||||||
|
|
||||||
if (process.ExitCode != 0)
|
if (process.ExitCode != 0)
|
||||||
{
|
{
|
||||||
@@ -421,4 +425,28 @@ namespace Framework.Database
|
|||||||
|
|
||||||
public abstract void PreparedStatements();
|
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