mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-29 22:21:37 -08:00
Implement migrations; fix #153
This commit is contained in:
@@ -60,6 +60,25 @@ bool Servatrice_DatabaseInterface::openDatabase()
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery *versionQuery = prepareQuery("select version from {prefix}_schema_version limit 1");
|
||||
if (!execSqlQuery(versionQuery)) {
|
||||
qCritical() << QString("[%1] Error opening database: unable to load database schema version (hint: ensure the cockatrice_schema_version exists)").arg(poolStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (versionQuery->next()) {
|
||||
const int dbversion = versionQuery->value(0).toInt();
|
||||
const int expectedversion = DATABASE_SCHEMA_VERSION;
|
||||
if(dbversion != expectedversion)
|
||||
{
|
||||
qCritical() << QString("[%1] Error opening database: the database schema version is too old, yum need to run the migrations to update it from version %2 to version %3").arg(poolStr).arg(dbversion).arg(expectedversion);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
qCritical() << QString("[%1] Error opening database: unable to load database schema version (hint: ensure the cockatrice_schema_version contains a single record)").arg(poolStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
// reset all prepared statements
|
||||
qDeleteAll(preparedStatements);
|
||||
preparedStatements.clear();
|
||||
|
||||
Reference in New Issue
Block a user