some primitive database stuff

This commit is contained in:
Blue 2023-12-08 19:26:16 -03:00
parent 89b80f0656
commit 319895db64
Signed by: blue
GPG key ID: 9B203B252A63EE38
10 changed files with 166 additions and 0 deletions

View file

@ -15,13 +15,27 @@ Server::Server():
db->setCredentials("pica", "pica");
db->setDatabase("pica");
bool connected = false;
try {
db->connect("/run/mysqld/mysqld.sock");
connected = true;
std::cout << "Successfully connected to the database" << std::endl;
} catch (const std::runtime_error& e) {
std::cerr << "Couldn't connect to the database: " << e.what() << std::endl;
}
if (connected) {
uint8_t version = db->getVersion();
std::cout << "Database version is " << std::to_string(version) << std::endl;
if (version == 0) {
db->executeFile("database/migrations/m0.sql");
std::cout << "Successfully migrated to version 1" << std::endl;
db->setVersion(1);
std::cout << "Database version is " << std::to_string(db->getVersion()) << " now" << std::endl;
}
}
router.addRoute("info", Server::info);
router.addRoute("env", Server::printEnvironment);
}