some primitive database stuff
This commit is contained in:
parent
89b80f0656
commit
319895db64
10 changed files with 166 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue