mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch: accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes they need. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
1.9 KiB
C++
61 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
struct Migration {
|
|
std::string data;
|
|
std::string name;
|
|
};
|
|
|
|
namespace MigrationRunner {
|
|
void RunMigrations();
|
|
void RunSQLiteMigrations();
|
|
|
|
/**
|
|
* Split a migration file into statements at the semicolons that end them. Semicolons inside comments
|
|
* (-- and /* *\/) and inside quoted strings or identifiers ('...', "...", `...`) are not statement ends.
|
|
* Comments are left out and statements that are only whitespace are skipped.
|
|
* @param backslashEscapes MySQL treats a backslash in a string as an escape; SQLite does not (Windows paths)
|
|
*/
|
|
inline std::vector<std::string> SplitStatements(std::string_view sql, bool backslashEscapes) {
|
|
std::vector<std::string> statements;
|
|
std::string current;
|
|
const auto flush = [&]() {
|
|
if (current.find_first_not_of(" \t\r\n") != std::string::npos) statements.push_back(current);
|
|
current.clear();
|
|
};
|
|
for (size_t i = 0; i < sql.size(); i++) {
|
|
const char c = sql[i];
|
|
const char next = i + 1 < sql.size() ? sql[i + 1] : '\0';
|
|
if (c == '-' && next == '-') {
|
|
while (i < sql.size() && sql[i] != '\n') i++;
|
|
current += '\n';
|
|
} else if (c == '/' && next == '*') {
|
|
const auto end = sql.find("*/", i + 2);
|
|
i = end == std::string_view::npos ? sql.size() : end + 1;
|
|
current += ' ';
|
|
} else if (c == '\'' || c == '"' || c == '`') {
|
|
// Copy the quoted text as is; a doubled quote (or a backslash, for MySQL) escapes one inside it
|
|
current += c;
|
|
for (i++; i < sql.size(); i++) {
|
|
current += sql[i];
|
|
if (backslashEscapes && sql[i] == '\\' && c != '`' && i + 1 < sql.size()) {
|
|
current += sql[++i];
|
|
} else if (sql[i] == c) {
|
|
if (i + 1 < sql.size() && sql[i + 1] == c) current += sql[++i];
|
|
else break;
|
|
}
|
|
}
|
|
} else if (c == ';') {
|
|
flush();
|
|
} else {
|
|
current += c;
|
|
}
|
|
}
|
|
flush();
|
|
return statements;
|
|
}
|
|
};
|