Prepare DB for storing of msg limit - OwnCloud.

This commit is contained in:
Martin Rotter 2017-09-13 12:12:40 +02:00
parent 7f16f5153c
commit 72337653c6
6 changed files with 29 additions and 2 deletions

View File

@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS OwnCloudAccounts (
password TEXT,
url TEXT NOT NULL,
force_update INTEGER(1) NOT NULL DEFAULT 0 CHECK (force_update >= 0 AND force_update <= 1),
msg_limit INTEGER NOT NULL DEFAULT -1 CHECK (msg_limit >= -1),
FOREIGN KEY (id) REFERENCES Accounts (id)
);

View File

@ -32,6 +32,7 @@ CREATE TABLE IF NOT EXISTS OwnCloudAccounts (
password TEXT,
url TEXT NOT NULL,
force_update INTEGER(1) NOT NULL CHECK (force_update >= 0 AND force_update <= 1) DEFAULT 0,
msg_limit INTEGER NOT NULL DEFAULT -1 CHECK (msg_limit >= -1),
FOREIGN KEY (id) REFERENCES Accounts (id)
);

View File

@ -0,0 +1,4 @@
ALTER TABLE OwnCloudAccounts
ADD COLUMN msg_limit INTEGER NOT NULL DEFAULT -1 CHECK (msg_limit >= -1);
-- !
UPDATE Information SET inf_value = '9' WHERE inf_key = 'schema_version';

View File

@ -0,0 +1,21 @@
CREATE TABLE backup_oa AS SELECT * FROM OwnCloudAccounts;
-- !
DROP TABLE OwnCloudAccounts;
-- !
CREATE TABLE IF NOT EXISTS OwnCloudAccounts (
id INTEGER,
username TEXT NOT NULL,
password TEXT,
url TEXT NOT NULL,
force_update INTEGER(1) NOT NULL CHECK (force_update >= 0 AND force_update <= 1) DEFAULT 0,
msg_limit INTEGER NOT NULL DEFAULT -1 CHECK (msg_limit >= -1),
FOREIGN KEY (id) REFERENCES Accounts (id)
);
-- !
INSERT INTO OwnCloudAccounts (id, username, password, url, force_update)
SELECT id, username, password, url, force_update FROM backup_oa;
-- !
DROP TABLE backup_oa;
-- !
UPDATE Information SET inf_value = '9' WHERE inf_key = 'schema_version';

View File

@ -121,7 +121,7 @@
#define APP_DB_SQLITE_FILE "database.db"
// Keep this in sync with schema versions declared in SQL initialization code.
#define APP_DB_SCHEMA_VERSION "8"
#define APP_DB_SCHEMA_VERSION "9"
#define APP_DB_UPDATE_FILE_PATTERN "db_update_%1_%2_%3.sql"
#define APP_DB_COMMENT_SPLIT "-- !\n"
#define APP_DB_NAME_PLACEHOLDER "##"

View File

@ -342,7 +342,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString& c
const QString installed_db_schema = query_db.value(0).toString();
query_db.finish();
if (installed_db_schema < APP_DB_SCHEMA_VERSION) {
if (installed_db_schema.toInt() < QString(APP_DB_SCHEMA_VERSION).toInt()) {
if (sqliteUpdateDatabaseSchema(database, installed_db_schema)) {
qDebug("Database schema was updated from '%s' to '%s' successully or it is already up to date.",
qPrintable(installed_db_schema),