Skip to content

Commit

Permalink
[fix] add new db fields (tag, ...) when creating new database
Browse files Browse the repository at this point in the history
Also create those fields for previous installs in error.
  • Loading branch information
Guillaume Bour committed Aug 2, 2020
1 parent a642016 commit d3d1fe6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion harbour-nextinpact.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\"
# get build date (timestamp) with: python -c 'import time; print(int(time.time()))'
DEFINES += BUILD_DATE='1594726620'

DBVERSION = 4
DBVERSION = 5
DBNAME = 'nextinpact.db'
#DBNAME = 'nextinpact-pre.db'
#DBNAME = 'nextinpact-dev.db'
Expand Down
31 changes: 31 additions & 0 deletions src/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ bool Database::init()
"new_comments INTEGER DEFAULT 1,"
// parent article ('brief' articles only, -1 for no parent)
"parent INTEGER DEFAULT -1,"
"tag TEXT,"
"subtag TEXT,"
"star INTEGER," // boolean: 0=false, 1=true
"subscriber INTEGER,"
"PRIMARY KEY (id, type)"
")");
qDebug() << query.lastError().text();
Expand Down Expand Up @@ -198,6 +202,33 @@ bool Database::migrate() {
}
}

/* forgot to add new v4 fields (tag, subtag, ...) in full create-table query
* So new users that just installed the app after 0.6.8 release (no previously exist db)
* had not those fields
*
* To fix that:
* - incrementing DB VERSION from 4 to 5
* - creating same fields than for version 4
* - increase stored version number to 5 even if fields creation failed
*/
if (version < 5) {
QStringList queries = {
"ALTER TABLE articles ADD COLUMN tag TEXT",
"ALTER TABLE articles ADD COLUMN subtag TEXT",
"ALTER TABLE articles ADD COLUMN star INTEGER", // boolean: 0=false, 1=true
"ALTER TABLE articles ADD COLUMN subscriber INTEGER" // boolean. access restricted (full access to subscribers)
//TODO: create index
};
if (!updater->exec(5, queries)) {
q.prepare("UPDATE config SET value='5' WHERE key='version'");
if (!q.exec()) {
qDebug() << "upgrade version field failed:" << q.lastError().text();
return false;
}
q.finish();
}
}

return true;
}

Expand Down

0 comments on commit d3d1fe6

Please sign in to comment.