mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
Add automatic cdclient migration runner support and setup (#789)
* Add automatic migrations for CDServer Add support to automatically migrate and update CDServers with new migrations. Also adds support to simplify the setup process by simply putting the fdb in the res folder and letting the server convert it to sqlite. This reduces the amount of back and forth when setting up a server. * Remove transaction language * Add DML execution `poggers` Add a way to execute DML commands through the sqlite connection on the server. * Make DML Commands more robust On the off chance the server is shutdown before the whole migration is run, lets just not add it to our "finished list" until the whole file is done. * Update README
This commit is contained in:
@@ -105,10 +105,34 @@ int main(int argc, char** argv) {
|
||||
const std::string cdclient_path = "./res/CDServer.sqlite";
|
||||
std::ifstream cdclient_fd(cdclient_path);
|
||||
if (!cdclient_fd.good()) {
|
||||
Game::logger->Log("WorldServer", "%s could not be opened", cdclient_path.c_str());
|
||||
return EXIT_FAILURE;
|
||||
Game::logger->Log("WorldServer", "%s could not be opened. Looking for cdclient.fdb to convert to sqlite.", cdclient_path.c_str());
|
||||
cdclient_fd.close();
|
||||
|
||||
const std::string cdclientFdbPath = "./res/cdclient.fdb";
|
||||
cdclient_fd.open(cdclientFdbPath);
|
||||
if (!cdclient_fd.good()) {
|
||||
Game::logger->Log(
|
||||
"WorldServer", "%s could not be opened."
|
||||
"Please move a cdclient.fdb or an already converted database to build/res.", cdclientFdbPath.c_str());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
Game::logger->Log("WorldServer", "Found %s. Clearing cdserver migration_history then copying and converting to sqlite.", cdclientFdbPath.c_str());
|
||||
auto stmt = Database::CreatePreppedStmt(R"#(DELETE FROM migration_history WHERE name LIKE "%cdserver%";)#");
|
||||
stmt->executeUpdate();
|
||||
delete stmt;
|
||||
cdclient_fd.close();
|
||||
|
||||
std::string res = "python3 ../thirdparty/docker-utils/utils/fdb_to_sqlite.py " + cdclientFdbPath;
|
||||
int r = system(res.c_str());
|
||||
if (r != 0) {
|
||||
Game::logger->Log("MasterServer", "Failed to convert fdb to sqlite");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (std::rename("./cdclient.sqlite", "./res/CDServer.sqlite") != 0) {
|
||||
Game::logger->Log("MasterServer", "failed to move cdclient file.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
cdclient_fd.close();
|
||||
|
||||
//Connect to CDClient
|
||||
try {
|
||||
@@ -120,6 +144,9 @@ int main(int argc, char** argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Run migrations should any need to be run.
|
||||
MigrationRunner::RunSQLiteMigrations();
|
||||
|
||||
//Get CDClient initial information
|
||||
try {
|
||||
CDClientManager::Instance()->Initialize();
|
||||
|
Reference in New Issue
Block a user