Commit b9fe1550 authored by Matthieu Gallien's avatar Matthieu Gallien

fix upgrades from 0.3 stable version

Summary: Upgrades from 0.3 version work again

Test Plan: Tests are OK

Reviewers: #elisa, ngraham

Reviewed By: ngraham

Tags: #elisa

Differential Revision: https://phabricator.kde.org/D20944
parent 9fd1e7bc
......@@ -20,6 +20,8 @@
#include "databaseinterface.h"
#include "musicaudiotrack.h"
#include "config-upnp-qt.h"
#include <QObject>
#include <QUrl>
#include <QString>
......@@ -4843,6 +4845,41 @@ private Q_SLOTS:
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
QCOMPARE(musicDbCleanedDatabaseSpy.count(), 1);
}
void upgradeFromStableVersion()
{
auto dbTestFile = QString{QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/elisaDatabase.v0.3.db")};
auto dbOriginFile = QString{QStringLiteral(LOCAL_FILE_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/elisaDatabase.v0.3.db")};
QFile::remove(dbTestFile);
QFile::copy(dbOriginFile, dbTestFile);
DatabaseInterface musicDb;
musicDb.init(QStringLiteral("testDb"), dbTestFile);
QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded);
QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded);
QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded);
QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved);
QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved);
QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved);
QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified);
QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified);
QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError);
QCOMPARE(musicDb.allAlbumsData().count(), 5);
QCOMPARE(musicDb.allArtistsData().count(), 7);
QCOMPARE(musicDb.allTracksData().count(), 22);
QCOMPARE(musicDbArtistAddedSpy.count(), 0);
QCOMPARE(musicDbAlbumAddedSpy.count(), 0);
QCOMPARE(musicDbTrackAddedSpy.count(), 0);
QCOMPARE(musicDbArtistRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
}
};
QTEST_GUILESS_MAIN(DatabaseInterfaceTests)
......
......@@ -1145,7 +1145,6 @@ void DatabaseInterface::initDatabase()
listTables = d->mTracksDatabase.tables();
}
checkDatabaseSchema();
listTables = d->mTracksDatabase.tables();
if (listTables.contains(QStringLiteral("DatabaseVersionV5")) &&
......@@ -1153,6 +1152,8 @@ void DatabaseInterface::initDatabase()
upgradeDatabaseV9();
upgradeDatabaseV11();
upgradeDatabaseV12();
checkDatabaseSchema();
} else if (listTables.contains(QStringLiteral("DatabaseVersionV9"))) {
if (!listTables.contains(QStringLiteral("DatabaseVersionV11"))) {
upgradeDatabaseV11();
......@@ -1160,6 +1161,8 @@ void DatabaseInterface::initDatabase()
if (!listTables.contains(QStringLiteral("DatabaseVersionV12"))) {
upgradeDatabaseV12();
}
checkDatabaseSchema();
} else {
createDatabaseV9();
upgradeDatabaseV11();
......@@ -1485,7 +1488,6 @@ void DatabaseInterface::upgradeDatabaseV9()
"`ArtistName` VARCHAR(55), "
"`AlbumPath` VARCHAR(255) NOT NULL, "
"`CoverFileName` VARCHAR(255) NOT NULL, "
"`AlbumInternalID` VARCHAR(55), "
"UNIQUE (`Title`, `ArtistName`, `AlbumPath`), "
"CONSTRAINT fk_artists FOREIGN KEY (`ArtistName`) REFERENCES `Artists`(`Name`) "
"ON DELETE CASCADE)"));
......@@ -1505,8 +1507,7 @@ void DatabaseInterface::upgradeDatabaseV9()
"album.`Title`, "
"artist.`Name`, "
"album.`AlbumPath`, "
"album.`CoverFileName`, "
"album.`AlbumInternalID` "
"album.`CoverFileName` "
"FROM "
"`Albums` album, "
"`AlbumsArtists` albumArtistMapping, "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment