2019-05-01 15:50:19 +08:00
|
|
|
/*
|
|
|
|
Copyright © 2019 by The qTox Project Contributors
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "src/persistence/db/rawdatabase.h"
|
2022-03-23 07:58:58 +08:00
|
|
|
#include "src/persistence/db/upgrades/dbupgrader.h"
|
2022-03-19 08:42:59 +08:00
|
|
|
#include "src/core/toxfile.h"
|
2019-05-01 15:50:19 +08:00
|
|
|
|
2022-03-25 17:25:46 +08:00
|
|
|
#include "dbutility/dbutility.h"
|
|
|
|
|
2019-05-01 15:50:19 +08:00
|
|
|
#include <QString>
|
2022-03-26 07:03:19 +08:00
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QtTest/QtTest>
|
2019-05-01 15:50:19 +08:00
|
|
|
|
2019-10-12 16:36:11 +08:00
|
|
|
#include <algorithm>
|
2022-03-25 17:25:46 +08:00
|
|
|
#include <array>
|
2019-05-01 15:50:19 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2022-03-19 08:42:59 +08:00
|
|
|
namespace {
|
|
|
|
bool insertFileId(RawDatabase& db, int row, bool valid)
|
|
|
|
{
|
|
|
|
QByteArray validResumeId(32, 1);
|
|
|
|
QByteArray invalidResumeId;
|
|
|
|
|
|
|
|
QByteArray resumeId;
|
|
|
|
if (valid) {
|
|
|
|
resumeId = validResumeId;
|
|
|
|
} else {
|
|
|
|
resumeId = invalidResumeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<RawDatabase::Query> upgradeQueries;
|
|
|
|
upgradeQueries += RawDatabase::Query(
|
|
|
|
QString("INSERT INTO file_transfers "
|
|
|
|
" (id, message_type, sender_alias, "
|
|
|
|
" file_restart_id, file_name, file_path, "
|
|
|
|
" file_hash, file_size, direction, file_state) "
|
|
|
|
"VALUES ( "
|
|
|
|
" %1, "
|
|
|
|
" 'F', "
|
|
|
|
" 1, "
|
|
|
|
" ?, "
|
|
|
|
" %2, "
|
|
|
|
" %3, "
|
|
|
|
" %4, "
|
|
|
|
" 1, "
|
|
|
|
" 1, "
|
|
|
|
" %5 "
|
|
|
|
");")
|
|
|
|
.arg(row)
|
|
|
|
.arg("\"fooname\"")
|
|
|
|
.arg("\"foo/path\"")
|
|
|
|
.arg("\"foohash\"")
|
|
|
|
.arg(ToxFile::CANCELED)
|
|
|
|
, {resumeId});
|
|
|
|
return db.execNow(upgradeQueries);
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2019-05-01 15:50:19 +08:00
|
|
|
class TestDbSchema : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
2022-03-26 07:03:19 +08:00
|
|
|
void init();
|
|
|
|
void cleanup();
|
2019-05-01 15:50:19 +08:00
|
|
|
void testCreation();
|
|
|
|
void testIsNewDb();
|
|
|
|
void test0to1();
|
fix(history): move stuck pending message into broken_messages table
Fix #5776
Due to a long standing bug, faux offline message have been able to become stuck
going back years. Because of recent fixes to history loading, faux offline
messages will correctly all be sent on connection, but this causes an issue of
long stuck messages suddenly being delivered to a friend, out of context,
creating a confusing interaction. To work around this, this upgrade moves any
faux offline messages in a chat that are older than the last successfully
delivered message, indicating they were stuck, to a new table,
`broken_messages`, preventing them from ever being sent in the future.
2019-10-06 16:23:24 +08:00
|
|
|
void test1to2();
|
2019-10-11 14:13:26 +08:00
|
|
|
void test2to3();
|
2019-10-12 08:15:33 +08:00
|
|
|
void test3to4();
|
2019-05-01 22:55:49 +08:00
|
|
|
void test4to5();
|
2019-11-17 18:19:57 +08:00
|
|
|
void test5to6();
|
2021-01-24 06:26:55 +08:00
|
|
|
void test6to7();
|
2021-03-01 03:19:24 +08:00
|
|
|
// test7to8 omitted, version only upgrade, versions are not verified in this
|
2019-04-23 14:17:55 +08:00
|
|
|
// test8to9 omitted, data corruption correction upgrade with no schema change
|
2022-03-19 08:42:59 +08:00
|
|
|
void test9to10();
|
refactor(History): Split peers table into chats and authors
peers had combined meaning, both being referenced by history for which
chat a message was in, and being reference by aliases for who authored a
message. This means that peers had conceptually different sub-groups:
all friends are both a chat and an author, but self is an author but not
a chat. With the addition of group chats this is amplified by groups
themselves being chats but not authors, and group members being authors
but not chats. Instead of having four sub-groups all within peers,
splitting peers into chats and authors gives a clean mapping,
simplifying interactions with the data.
In the new chats and authors tables, store what used to be a public_key
string as a BLOB, since it’s inherently a 32-byte binary value in both
cases. Call the public_key a UUID for chats, since group IDs are not
defined as public keys by toxcore.
Even though the data change is quite minor, the upgrade is large because
of SQLite's lack of support for modifying foreign key constrains for
existing tables. This means when peers are moved to new tables, all
tables referencing peers need to be cloned with a new foreign key
constraint, as well as all tables referencing those, recursively.
2022-03-22 19:43:27 +08:00
|
|
|
// test10to11 handled in dbTo11_test
|
2021-03-01 03:19:24 +08:00
|
|
|
// test suite
|
2021-01-24 06:26:55 +08:00
|
|
|
|
2019-05-01 15:50:19 +08:00
|
|
|
private:
|
2022-03-26 07:03:19 +08:00
|
|
|
std::unique_ptr<QTemporaryFile> testDatabaseFile;
|
2019-05-01 15:50:19 +08:00
|
|
|
};
|
|
|
|
|
2022-03-26 07:03:19 +08:00
|
|
|
void TestDbSchema::init()
|
|
|
|
{
|
|
|
|
testDatabaseFile = std::unique_ptr<QTemporaryFile>(new QTemporaryFile());
|
|
|
|
// fileName is only defined once the file is opened. Since RawDatabase
|
|
|
|
// will be openening the file itself not using QFile, open and close it now.
|
|
|
|
QVERIFY(testDatabaseFile->open());
|
|
|
|
testDatabaseFile->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestDbSchema::cleanup()
|
|
|
|
{
|
|
|
|
testDatabaseFile.reset();
|
|
|
|
}
|
|
|
|
|
2019-05-01 15:50:19 +08:00
|
|
|
void TestDbSchema::testCreation()
|
|
|
|
{
|
|
|
|
QVector<RawDatabase::Query> queries;
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-09 20:15:26 +08:00
|
|
|
QVERIFY(DbUpgrader::createCurrentSchema(*db));
|
refactor(History): Split peers table into chats and authors
peers had combined meaning, both being referenced by history for which
chat a message was in, and being reference by aliases for who authored a
message. This means that peers had conceptually different sub-groups:
all friends are both a chat and an author, but self is an author but not
a chat. With the addition of group chats this is amplified by groups
themselves being chats but not authors, and group members being authors
but not chats. Instead of having four sub-groups all within peers,
splitting peers into chats and authors gives a clean mapping,
simplifying interactions with the data.
In the new chats and authors tables, store what used to be a public_key
string as a BLOB, since it’s inherently a 32-byte binary value in both
cases. Call the public_key a UUID for chats, since group IDs are not
defined as public keys by toxcore.
Even though the data change is quite minor, the upgrade is large because
of SQLite's lack of support for modifying foreign key constrains for
existing tables. This means when peers are moved to new tables, all
tables referencing peers need to be cloned with a new foreign key
constraint, as well as all tables referencing those, recursively.
2022-03-22 19:43:27 +08:00
|
|
|
DbUtility::verifyDb(db, DbUtility::schema11);
|
2019-05-01 15:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestDbSchema::testIsNewDb()
|
|
|
|
{
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2019-10-07 15:08:01 +08:00
|
|
|
bool success = false;
|
2022-03-09 20:15:26 +08:00
|
|
|
bool newDb = DbUpgrader::isNewDb(db, success);
|
2019-10-07 15:08:01 +08:00
|
|
|
QVERIFY(success);
|
|
|
|
QVERIFY(newDb == true);
|
2022-03-26 07:03:19 +08:00
|
|
|
db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema0);
|
2022-03-09 20:15:26 +08:00
|
|
|
newDb = DbUpgrader::isNewDb(db, success);
|
2019-10-07 15:08:01 +08:00
|
|
|
QVERIFY(success);
|
|
|
|
QVERIFY(newDb == false);
|
2019-05-01 15:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestDbSchema::test0to1()
|
|
|
|
{
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema0);
|
2022-03-09 20:15:26 +08:00
|
|
|
QVERIFY(DbUpgrader::dbSchema0to1(*db));
|
2022-03-25 17:25:46 +08:00
|
|
|
DbUtility::verifyDb(db, DbUtility::schema1);
|
2019-05-01 15:50:19 +08:00
|
|
|
}
|
|
|
|
|
fix(history): move stuck pending message into broken_messages table
Fix #5776
Due to a long standing bug, faux offline message have been able to become stuck
going back years. Because of recent fixes to history loading, faux offline
messages will correctly all be sent on connection, but this causes an issue of
long stuck messages suddenly being delivered to a friend, out of context,
creating a confusing interaction. To work around this, this upgrade moves any
faux offline messages in a chat that are older than the last successfully
delivered message, indicating they were stuck, to a new table,
`broken_messages`, preventing them from ever being sent in the future.
2019-10-06 16:23:24 +08:00
|
|
|
void TestDbSchema::test1to2()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Due to a long standing bug, faux offline message have been able to become stuck
|
|
|
|
going back years. Because of recent fixes to history loading, faux offline
|
|
|
|
messages will correctly all be sent on connection, but this causes an issue of
|
|
|
|
long stuck messages suddenly being delivered to a friend, out of context,
|
|
|
|
creating a confusing interaction. To work around this, this upgrade moves any
|
|
|
|
faux offline messages in a chat that are older than the last successfully
|
|
|
|
delivered message, indicating they were stuck, to a new table,
|
|
|
|
`broken_messages`, preventing them from ever being sent in the future.
|
|
|
|
|
|
|
|
https://github.com/qTox/qTox/issues/5776
|
|
|
|
*/
|
|
|
|
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema1);
|
fix(history): move stuck pending message into broken_messages table
Fix #5776
Due to a long standing bug, faux offline message have been able to become stuck
going back years. Because of recent fixes to history loading, faux offline
messages will correctly all be sent on connection, but this causes an issue of
long stuck messages suddenly being delivered to a friend, out of context,
creating a confusing interaction. To work around this, this upgrade moves any
faux offline messages in a chat that are older than the last successfully
delivered message, indicating they were stuck, to a new table,
`broken_messages`, preventing them from ever being sent in the future.
2019-10-06 16:23:24 +08:00
|
|
|
|
|
|
|
const QString myPk = "AC18841E56CCDEE16E93E10E6AB2765BE54277D67F1372921B5B418A6B330D3D";
|
|
|
|
const QString friend1Pk = "FE34BC6D87B66E958C57BBF205F9B79B62BE0AB8A4EFC1F1BB9EC4D0D8FB0663";
|
|
|
|
const QString friend2Pk = "2A1CBCE227549459C0C20F199DB86AD9BCC436D35BAA1825FFD4B9CA3290D200";
|
|
|
|
|
|
|
|
QVector<RawDatabase::Query> queries;
|
|
|
|
queries += QString("INSERT INTO peers (id, public_key) VALUES (%1, '%2')").arg(0).arg(myPk);
|
|
|
|
queries += QString("INSERT INTO peers (id, public_key) VALUES (%1, '%2')").arg(1).arg(friend1Pk);
|
|
|
|
queries += QString("INSERT INTO peers (id, public_key) VALUES (%1, '%2')").arg(2).arg(friend2Pk);
|
|
|
|
|
|
|
|
// friend 1
|
|
|
|
// first message in chat is pending - but the second is delivered. This message is "broken"
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (1, 1, 1, ?, 0)",
|
|
|
|
{"first message in chat, pending and stuck"}};
|
|
|
|
queries += {"INSERT INTO faux_offline_pending (id) VALUES ("
|
|
|
|
" last_insert_rowid()"
|
|
|
|
");"};
|
|
|
|
// second message is delivered, causing the first to be considered broken
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (2, 2, 1, ?, 0)",
|
|
|
|
{"second message in chat, delivered"}};
|
|
|
|
|
|
|
|
// third message is pending - this is a normal pending message. It should be untouched.
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (3, 3, 1, ?, 0)",
|
|
|
|
{"third message in chat, pending"}};
|
|
|
|
queries += {"INSERT INTO faux_offline_pending (id) VALUES ("
|
|
|
|
" last_insert_rowid()"
|
|
|
|
");"};
|
|
|
|
|
|
|
|
// friend 2
|
|
|
|
// first message is delivered.
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (4, 4, 2, ?, 2)",
|
|
|
|
{"first message by friend in chat, delivered"}};
|
|
|
|
|
|
|
|
// second message is also delivered.
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (5, 5, 2, ?, 0)",
|
|
|
|
{"first message by us in chat, delivered"}};
|
|
|
|
|
|
|
|
// third message is pending, but not broken since there are no delivered messages after it.
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (6, 6, 2, ?, 0)",
|
|
|
|
{"last message in chat, by us, pending"}};
|
|
|
|
queries += {"INSERT INTO faux_offline_pending (id) VALUES ("
|
|
|
|
" last_insert_rowid()"
|
|
|
|
");"};
|
|
|
|
|
|
|
|
QVERIFY(db->execNow(queries));
|
2022-03-09 20:15:26 +08:00
|
|
|
QVERIFY(DbUpgrader::dbSchema1to2(*db));
|
2022-03-25 17:25:46 +08:00
|
|
|
DbUtility::verifyDb(db, DbUtility::schema2);
|
fix(history): move stuck pending message into broken_messages table
Fix #5776
Due to a long standing bug, faux offline message have been able to become stuck
going back years. Because of recent fixes to history loading, faux offline
messages will correctly all be sent on connection, but this causes an issue of
long stuck messages suddenly being delivered to a friend, out of context,
creating a confusing interaction. To work around this, this upgrade moves any
faux offline messages in a chat that are older than the last successfully
delivered message, indicating they were stuck, to a new table,
`broken_messages`, preventing them from ever being sent in the future.
2019-10-06 16:23:24 +08:00
|
|
|
|
|
|
|
long brokenCount = -1;
|
|
|
|
RawDatabase::Query brokenCountQuery = {"SELECT COUNT(*) FROM broken_messages;", [&](const QVector<QVariant>& row) {
|
|
|
|
brokenCount = row[0].toLongLong();
|
|
|
|
}};
|
|
|
|
QVERIFY(db->execNow(brokenCountQuery));
|
|
|
|
QVERIFY(brokenCount == 1); // only friend 1's first message is "broken"
|
|
|
|
|
|
|
|
int fauxOfflineCount = -1;
|
|
|
|
RawDatabase::Query fauxOfflineCountQuery = {"SELECT COUNT(*) FROM faux_offline_pending;", [&](const QVector<QVariant>& row) {
|
|
|
|
fauxOfflineCount = row[0].toLongLong();
|
|
|
|
}};
|
|
|
|
QVERIFY(db->execNow(fauxOfflineCountQuery));
|
|
|
|
// both friend 1's third message and friend 2's third message should still be pending.
|
|
|
|
//The broken message should no longer be pending.
|
|
|
|
QVERIFY(fauxOfflineCount == 2);
|
|
|
|
|
|
|
|
int totalHisoryCount = -1;
|
|
|
|
RawDatabase::Query totalHistoryCountQuery = {"SELECT COUNT(*) FROM history;", [&](const QVector<QVariant>& row) {
|
|
|
|
totalHisoryCount = row[0].toLongLong();
|
|
|
|
}};
|
|
|
|
QVERIFY(db->execNow(totalHistoryCountQuery));
|
|
|
|
QVERIFY(totalHisoryCount == 6); // all messages should still be in history.
|
|
|
|
}
|
|
|
|
|
2019-10-11 14:13:26 +08:00
|
|
|
void TestDbSchema::test2to3()
|
|
|
|
{
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema2);
|
2019-10-11 14:13:26 +08:00
|
|
|
|
|
|
|
// since we don't enforce foreign key contraints in the db, we can stick in IDs to other tables
|
|
|
|
// to avoid generating proper entries for peers and aliases tables, since they aren't actually
|
|
|
|
// relevant for the test.
|
|
|
|
|
|
|
|
QVector<RawDatabase::Query> queries;
|
|
|
|
// pending message, should be moved out
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (1, 1, 0, ?, 0)",
|
|
|
|
{"/me "}};
|
|
|
|
queries += {"INSERT INTO faux_offline_pending (id) VALUES ("
|
|
|
|
" last_insert_rowid()"
|
|
|
|
");"};
|
|
|
|
|
|
|
|
// non pending message with the content "/me ". Maybe it was sent by a friend using a different client.
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (2, 2, 0, ?, 2)",
|
|
|
|
{"/me "}};
|
|
|
|
|
|
|
|
// non pending message sent by us
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (3, 3, 0, ?, 1)",
|
|
|
|
{"a normal message"}};
|
|
|
|
|
|
|
|
// pending normal message sent by us
|
|
|
|
queries += RawDatabase::Query{
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (4, 3, 0, ?, 1)",
|
|
|
|
{"a normal faux offline message"}};
|
|
|
|
queries += {"INSERT INTO faux_offline_pending (id) VALUES ("
|
|
|
|
" last_insert_rowid()"
|
|
|
|
");"};
|
|
|
|
QVERIFY(db->execNow(queries));
|
2022-03-09 20:15:26 +08:00
|
|
|
QVERIFY(DbUpgrader::dbSchema2to3(*db));
|
2019-10-11 14:13:26 +08:00
|
|
|
|
|
|
|
long brokenCount = -1;
|
|
|
|
RawDatabase::Query brokenCountQuery = {"SELECT COUNT(*) FROM broken_messages;", [&](const QVector<QVariant>& row) {
|
|
|
|
brokenCount = row[0].toLongLong();
|
|
|
|
}};
|
|
|
|
QVERIFY(db->execNow(brokenCountQuery));
|
|
|
|
QVERIFY(brokenCount == 1);
|
|
|
|
|
|
|
|
int fauxOfflineCount = -1;
|
|
|
|
RawDatabase::Query fauxOfflineCountQuery = {"SELECT COUNT(*) FROM faux_offline_pending;", [&](const QVector<QVariant>& row) {
|
|
|
|
fauxOfflineCount = row[0].toLongLong();
|
|
|
|
}};
|
|
|
|
QVERIFY(db->execNow(fauxOfflineCountQuery));
|
|
|
|
QVERIFY(fauxOfflineCount == 1);
|
|
|
|
|
|
|
|
int totalHisoryCount = -1;
|
|
|
|
RawDatabase::Query totalHistoryCountQuery = {"SELECT COUNT(*) FROM history;", [&](const QVector<QVariant>& row) {
|
|
|
|
totalHisoryCount = row[0].toLongLong();
|
|
|
|
}};
|
|
|
|
QVERIFY(db->execNow(totalHistoryCountQuery));
|
|
|
|
QVERIFY(totalHisoryCount == 4);
|
|
|
|
|
2022-03-25 17:25:46 +08:00
|
|
|
DbUtility::verifyDb(db, DbUtility::schema3);
|
2019-10-11 14:13:26 +08:00
|
|
|
}
|
|
|
|
|
2019-10-12 08:15:33 +08:00
|
|
|
void TestDbSchema::test3to4()
|
|
|
|
{
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema3);
|
2022-03-09 20:15:26 +08:00
|
|
|
QVERIFY(DbUpgrader::dbSchema3to4(*db));
|
2022-03-25 17:25:46 +08:00
|
|
|
DbUtility::verifyDb(db, DbUtility::schema4);
|
2019-10-12 08:15:33 +08:00
|
|
|
}
|
|
|
|
|
2019-05-01 22:55:49 +08:00
|
|
|
void TestDbSchema::test4to5()
|
|
|
|
{
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema4);
|
2022-03-09 20:15:26 +08:00
|
|
|
QVERIFY(DbUpgrader::dbSchema4to5(*db));
|
2022-03-25 17:25:46 +08:00
|
|
|
DbUtility::verifyDb(db, DbUtility::schema5);
|
2019-05-01 22:55:49 +08:00
|
|
|
}
|
|
|
|
|
2019-11-17 18:19:57 +08:00
|
|
|
void TestDbSchema::test5to6()
|
|
|
|
{
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema5);
|
2022-03-09 20:15:26 +08:00
|
|
|
QVERIFY(DbUpgrader::dbSchema5to6(*db));
|
2022-03-25 17:25:46 +08:00
|
|
|
DbUtility::verifyDb(db, DbUtility::schema6);
|
2019-11-17 18:19:57 +08:00
|
|
|
}
|
|
|
|
|
2021-01-24 06:26:55 +08:00
|
|
|
void TestDbSchema::test6to7()
|
|
|
|
{
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2021-01-24 06:26:55 +08:00
|
|
|
// foreign_keys are enabled by History constructor and required for this upgrade to work on older sqlite versions
|
|
|
|
db->execNow(
|
|
|
|
"PRAGMA foreign_keys = ON;");
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema6);
|
2022-03-09 20:15:26 +08:00
|
|
|
QVERIFY(DbUpgrader::dbSchema6to7(*db));
|
2022-03-25 17:25:46 +08:00
|
|
|
DbUtility::verifyDb(db, DbUtility::schema7);
|
2021-01-24 06:26:55 +08:00
|
|
|
}
|
|
|
|
|
2022-03-19 08:42:59 +08:00
|
|
|
void TestDbSchema::test9to10()
|
|
|
|
{
|
2022-03-26 07:03:19 +08:00
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};
|
2022-03-25 17:25:46 +08:00
|
|
|
createSchemaAtVersion(db, DbUtility::schema9);
|
2022-03-19 08:42:59 +08:00
|
|
|
|
|
|
|
QVERIFY(insertFileId(*db, 1, true));
|
|
|
|
QVERIFY(insertFileId(*db, 2, true));
|
|
|
|
QVERIFY(insertFileId(*db, 3, false));
|
|
|
|
QVERIFY(insertFileId(*db, 4, true));
|
|
|
|
QVERIFY(insertFileId(*db, 5, false));
|
|
|
|
QVERIFY(DbUpgrader::dbSchema9to10(*db));
|
|
|
|
int numHealed = 0;
|
|
|
|
int numUnchanged = 0;
|
|
|
|
QVERIFY(db->execNow(RawDatabase::Query("SELECT file_restart_id from file_transfers;",
|
|
|
|
[&](const QVector<QVariant>& row) {
|
|
|
|
auto resumeId = row[0].toByteArray();
|
|
|
|
if (resumeId == QByteArray(32, 0)) {
|
|
|
|
++numHealed;
|
|
|
|
} else if (resumeId == QByteArray(32, 1)) {
|
|
|
|
++numUnchanged;
|
|
|
|
} else {
|
|
|
|
QFAIL("Invalid file_restart_id");
|
|
|
|
}
|
|
|
|
})));
|
|
|
|
QVERIFY(numHealed == 2);
|
|
|
|
QVERIFY(numUnchanged == 3);
|
2022-03-25 17:25:46 +08:00
|
|
|
verifyDb(db, DbUtility::schema10);
|
2022-03-19 08:42:59 +08:00
|
|
|
}
|
|
|
|
|
2019-05-01 15:50:19 +08:00
|
|
|
QTEST_GUILESS_MAIN(TestDbSchema)
|
|
|
|
#include "dbschema_test.moc"
|