Implement migrations; fix #153
This commit is contained in:
parent
2de99475b0
commit
135205d368
4 changed files with 45 additions and 0 deletions
13
servatrice/migrations/servatrice_0000_to_0001.sql
Normal file
13
servatrice/migrations/servatrice_0000_to_0001.sql
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
-- Servatrice db migration from version 0 to version 1
|
||||||
|
|
||||||
|
-- FIX #153
|
||||||
|
CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` (
|
||||||
|
`version` int(7) unsigned NOT NULL,
|
||||||
|
PRIMARY KEY (`version`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
INSERT INTO cockatrice_schema_version VALUES(1);
|
||||||
|
|
||||||
|
-- FIX #1119
|
||||||
|
ALTER TABLE `cockatrice_rooms_gametypes` DROP PRIMARY KEY;
|
||||||
|
ALTER TABLE `cockatrice_rooms_gametypes` ADD KEY (`id_room`);
|
|
@ -11,6 +11,17 @@ SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
|
||||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||||
/*!40101 SET NAMES utf8 */;
|
/*!40101 SET NAMES utf8 */;
|
||||||
|
|
||||||
|
-- Every time the database schema changes, the schema version number
|
||||||
|
-- must be incremented. Also remember to update the corresponding
|
||||||
|
-- number in servatrice/src/servatrice_database_interface.h
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` (
|
||||||
|
`version` int(7) unsigned NOT NULL,
|
||||||
|
PRIMARY KEY (`version`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
INSERT INTO cockatrice_schema_version VALUES(1);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` (
|
CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` (
|
||||||
`id` int(7) unsigned zerofill NOT NULL auto_increment,
|
`id` int(7) unsigned zerofill NOT NULL auto_increment,
|
||||||
`id_folder` int(7) unsigned zerofill NOT NULL,
|
`id_folder` int(7) unsigned zerofill NOT NULL,
|
||||||
|
|
|
@ -60,6 +60,25 @@ bool Servatrice_DatabaseInterface::openDatabase()
|
||||||
return false;
|
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
|
// reset all prepared statements
|
||||||
qDeleteAll(preparedStatements);
|
qDeleteAll(preparedStatements);
|
||||||
preparedStatements.clear();
|
preparedStatements.clear();
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "server_database_interface.h"
|
#include "server_database_interface.h"
|
||||||
|
|
||||||
|
#define DATABASE_SCHEMA_VERSION 1
|
||||||
|
|
||||||
class Servatrice;
|
class Servatrice;
|
||||||
|
|
||||||
class Servatrice_DatabaseInterface : public Server_DatabaseInterface {
|
class Servatrice_DatabaseInterface : public Server_DatabaseInterface {
|
||||||
|
|
Loading…
Reference in a new issue