mirror of https://github.com/nymea/nymea.git
Fix db version error message
parent
e106b66a70
commit
951ad27e89
|
|
@ -476,7 +476,7 @@ bool LogEngine::migrateDatabaseVersion2to3()
|
|||
}
|
||||
entryCount = countQuery.value(0).toInt();
|
||||
|
||||
qCDebug(dcLogEngine()) << "Entries to migrate:" << entryCount;
|
||||
qCDebug(dcLogEngine()) << "Found" << entryCount << "entries to migrate.";
|
||||
|
||||
// Select all entries
|
||||
QSqlQuery selectQuery = m_db.exec("SELECT * FROM entries;");
|
||||
|
|
@ -545,17 +545,22 @@ bool LogEngine::initDB()
|
|||
QSqlQuery query = m_db.exec("SELECT data FROM metadata WHERE key = 'version';");
|
||||
if (query.next()) {
|
||||
int version = query.value("data").toInt();
|
||||
|
||||
// Migration from 2 -> 3 (serialize values in order to store QVariant information)
|
||||
if (DB_SCHEMA_VERSION == 3 && version == 2) {
|
||||
if (!migrateDatabaseVersion2to3()) {
|
||||
qCWarning(dcLogEngine()) << "Migration process failed.";
|
||||
return false;
|
||||
} else {
|
||||
// Successfully migrated
|
||||
version = DB_SCHEMA_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
if (version != DB_SCHEMA_VERSION) {
|
||||
qCWarning(dcLogEngine) << "Log schema version not matching! Schema upgrade not implemented yet. Logging might fail.";
|
||||
} else {
|
||||
qCDebug(dcLogEngine) << QString("Log database schema version \"%1\" matches").arg(DB_SCHEMA_VERSION);
|
||||
qCDebug(dcLogEngine) << QString("Log database schema version \"%1\" matches").arg(DB_SCHEMA_VERSION).toLatin1().data();
|
||||
}
|
||||
} else {
|
||||
qCWarning(dcLogEngine) << "Broken log database. Version not found in metadata table.";
|
||||
|
|
|
|||
|
|
@ -41,19 +41,18 @@ private slots:
|
|||
|
||||
TestLoggingLoading::TestLoggingLoading(QObject *parent): QObject(parent)
|
||||
{
|
||||
|
||||
Q_INIT_RESOURCE(loggingloading);
|
||||
}
|
||||
|
||||
void TestLoggingLoading::testLogMigration()
|
||||
{
|
||||
Q_INIT_RESOURCE(loggingloading);
|
||||
|
||||
// Create LogEngine with log db from resource file
|
||||
QString temporaryDbName = GuhSettings::settingsPath() + "/guhd-v2.sqlite";
|
||||
|
||||
if (QFile::exists(temporaryDbName))
|
||||
QVERIFY(QFile(temporaryDbName).remove());
|
||||
|
||||
// Copy v2 log db from resources to default settings path and set permissions
|
||||
QVERIFY(QFile::copy(":/guhd-v2.sqlite", temporaryDbName));
|
||||
QVERIFY(QFile::setPermissions(temporaryDbName, QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther));
|
||||
|
||||
|
|
@ -68,8 +67,6 @@ void TestLoggingLoading::testLogMigration()
|
|||
|
||||
void TestLoggingLoading::testLogfileRotation()
|
||||
{
|
||||
Q_INIT_RESOURCE(loggingloading);
|
||||
|
||||
// Create LogEngine with log db from resource file
|
||||
QString temporaryDbName = GuhSettings::settingsPath() + "/guhd-broken.sqlite";
|
||||
QString rotatedDbName = GuhSettings::settingsPath() + "/guhd-broken.sqlite.1";
|
||||
|
|
@ -81,6 +78,7 @@ void TestLoggingLoading::testLogfileRotation()
|
|||
if (QFile::exists(rotatedDbName))
|
||||
QVERIFY(QFile(rotatedDbName).remove());
|
||||
|
||||
// Copy broken log db from resources to default settings path and set permissions
|
||||
QVERIFY(QFile::copy(":/guhd-broken.sqlite", temporaryDbName));
|
||||
QVERIFY(QFile::setPermissions(temporaryDbName, QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther));
|
||||
|
||||
|
|
@ -117,7 +115,7 @@ void TestLoggingLoading::databaseSerializationTest_data()
|
|||
QTest::newRow("Double") << QVariant((double)2.34);
|
||||
QTest::newRow("Float") << QVariant((float)2.34);
|
||||
QTest::newRow("QColor") << QVariant(QColor(0,255,128));
|
||||
QTest::newRow("QByteArray") << QVariant(QByteArray("\nthisisatestarray\n"));
|
||||
QTest::newRow("QByteArray") << QVariant(QByteArray::fromHex("01FF332F762A"));
|
||||
QTest::newRow("QUuid") << QVariant(uuid);
|
||||
QTest::newRow("QVariantMap") << QVariant(variantMap);
|
||||
QTest::newRow("QVariantList") << QVariant(variantList);
|
||||
|
|
|
|||
Loading…
Reference in New Issue