mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2026-04-01 17:20:04 +00:00
DB v2 Tweaks
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
|
||||
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
|
||||
#include "mingw/mingw.mutex.h"
|
||||
@@ -134,9 +135,19 @@ void Database::checkMetaTable() {
|
||||
if (dbVersion > DATABASE_VERSION) {
|
||||
std::cout << "[FATAL] Server Build is incompatible with DB Version" << std::endl;
|
||||
exit(1);
|
||||
} else if (dbVersion < DATABASE_VERSION) {
|
||||
// we're gonna migrate; back up the DB
|
||||
try {
|
||||
std::cout << "[INFO] Backing up database" << std::endl;
|
||||
std::filesystem::copy_file(settings::DBPATH, settings::DBPATH + ".old." + std::to_string(dbVersion));
|
||||
}
|
||||
catch (std::filesystem::filesystem_error& e) {
|
||||
std::cout << "[FATAL] Failed to backup database before migration" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
while (dbVersion != DATABASE_VERSION){
|
||||
while (dbVersion != DATABASE_VERSION) {
|
||||
// db migrations
|
||||
std::cout << "[INFO] Migrating Database to Version " << dbVersion + 1 << std::endl;
|
||||
|
||||
@@ -158,7 +169,7 @@ void Database::checkMetaTable() {
|
||||
}
|
||||
|
||||
dbVersion++;
|
||||
std::cout << "[INFO] Successfull Database Migration to Version " << dbVersion << std::endl;
|
||||
std::cout << "[INFO] Successful Database Migration to Version " << dbVersion << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,14 +237,12 @@ void Database::createTables() {
|
||||
std::string read = stream.str();
|
||||
const char* sql = read.c_str();
|
||||
|
||||
dbCrit.lock();
|
||||
char* errMsg = 0;
|
||||
int rc = sqlite3_exec(db, sql, NULL, NULL, &errMsg);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cout << "[FATAL] Database failed to create tables: " << errMsg << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
dbCrit.unlock();
|
||||
}
|
||||
|
||||
int Database::getTableSize(std::string tableName) {
|
||||
|
||||
Reference in New Issue
Block a user