Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update database help message #2979

Merged
merged 3 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions src/database/mixxxdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,47 +70,47 @@ MixxxDb::MixxxDb(

bool MixxxDb::initDatabaseSchema(
const QSqlDatabase& database,
const QString& schemaFile,
int schemaVersion) {
int schemaVersion,
const QString& schemaFile) {
QString okToExit = tr("Click OK to exit.");
QString upgradeFailed = tr("Cannot upgrade database schema");
QString upgradeToVersionFailed =
tr("Unable to upgrade your database schema to version %1")
.arg(QString::number(schemaVersion));
QString helpEmail = tr("For help with database issues contact:") + "\n" +
"mixxx-devel@lists.sourceforge.net";

switch (SchemaManager(database).upgradeToSchemaVersion(schemaFile, schemaVersion)) {
case SchemaManager::Result::CurrentVersion:
case SchemaManager::Result::UpgradeSucceeded:
case SchemaManager::Result::NewerVersionBackwardsCompatible:
return true; // done
case SchemaManager::Result::UpgradeFailed:
QMessageBox::warning(
0, upgradeFailed,
upgradeToVersionFailed + "\n" +
tr("Your mixxxdb.sqlite file may be corrupt.") + "\n" +
tr("Try renaming it and restarting Mixxx.") + "\n" +
helpEmail + "\n\n" + okToExit,
QMessageBox::Ok);
return false; // abort
case SchemaManager::Result::NewerVersionIncompatible:
QMessageBox::warning(
0, upgradeFailed,
upgradeToVersionFailed + "\n" +
tr("Your mixxxdb.sqlite file was created by a newer "
"version of Mixxx and is incompatible.") +
"\n\n" + okToExit,
QMessageBox::Ok);
return false; // abort
case SchemaManager::Result::SchemaError:
QMessageBox::warning(
0, upgradeFailed,
upgradeToVersionFailed + "\n" +
tr("The database schema file is invalid.") + "\n" +
helpEmail + "\n\n" + okToExit,
QMessageBox::Ok);
return false; // abort
QString helpContact = tr("For help with database issues consult:") + "\n" +
"https://www.mixxx.org/support";

switch (SchemaManager(database).upgradeToSchemaVersion(schemaVersion, schemaFile)) {
case SchemaManager::Result::CurrentVersion:
case SchemaManager::Result::UpgradeSucceeded:
case SchemaManager::Result::NewerVersionBackwardsCompatible:
return true; // done
case SchemaManager::Result::UpgradeFailed:
QMessageBox::warning(0,
upgradeFailed,
upgradeToVersionFailed + "\n" +
tr("Your mixxxdb.sqlite file may be corrupt.") +
"\n" + tr("Try renaming it and restarting Mixxx.") +
"\n" + helpContact + "\n\n" + okToExit,
QMessageBox::Ok);
return false; // abort
case SchemaManager::Result::NewerVersionIncompatible:
QMessageBox::warning(0,
upgradeFailed,
upgradeToVersionFailed + "\n" +
tr("Your mixxxdb.sqlite file was created by a newer "
"version of Mixxx and is incompatible.") +
"\n\n" + okToExit,
QMessageBox::Ok);
return false; // abort
case SchemaManager::Result::SchemaError:
QMessageBox::warning(0,
upgradeFailed,
upgradeToVersionFailed + "\n" +
tr("The database schema file is invalid.") + "\n" +
helpContact + "\n\n" + okToExit,
QMessageBox::Ok);
return false; // abort
}
// Suppress compiler warning
DEBUG_ASSERT(!"unhandled switch/case");
Expand Down
4 changes: 2 additions & 2 deletions src/database/mixxxdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class MixxxDb : public QObject {

static bool initDatabaseSchema(
const QSqlDatabase& database,
const QString& schemaFile = kDefaultSchemaFile,
int schemaVersion = kRequiredSchemaVersion);
int schemaVersion = kRequiredSchemaVersion,
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
const QString& schemaFile = kDefaultSchemaFile);

explicit MixxxDb(
const UserSettingsPointer& pConfig,
Expand Down
3 changes: 1 addition & 2 deletions src/database/schemamanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ bool SchemaManager::isBackwardsCompatibleWithVersion(int targetVersion) const {
}

SchemaManager::Result SchemaManager::upgradeToSchemaVersion(
const QString& schemaFilename,
int targetVersion) {
int targetVersion, const QString& schemaFilename) {
VERIFY_OR_DEBUG_ASSERT(m_currentVersion >= 0) {
return Result::UpgradeFailed;
}
Expand Down
4 changes: 1 addition & 3 deletions src/database/schemamanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class SchemaManager {

bool isBackwardsCompatibleWithVersion(int targetVersion) const;

Result upgradeToSchemaVersion(
const QString& schemaFilename,
int targetVersion);
Result upgradeToSchemaVersion(int targetVersion, const QString& schemaFilename);

private:
QSqlDatabase m_database;
Expand Down
37 changes: 18 additions & 19 deletions src/test/schemamanager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ TEST_F(SchemaManagerTest, CanUpgradeFreshDatabaseToRequiredVersion) {
{
SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, MixxxDb::kRequiredSchemaVersion);
MixxxDb::kRequiredSchemaVersion, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::UpgradeSucceeded, result);
}
// Subsequent upgrade(s)
{
SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, MixxxDb::kRequiredSchemaVersion);
MixxxDb::kRequiredSchemaVersion, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::CurrentVersion, result);
}
}

TEST_F(SchemaManagerTest, NonExistentSchema) {
SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
":file_doesnt_exist.xml", MixxxDb::kRequiredSchemaVersion);
MixxxDb::kRequiredSchemaVersion, ":file_doesnt_exist.xml");
EXPECT_EQ(SchemaManager::Result::SchemaError, result);
}

Expand All @@ -60,22 +60,22 @@ TEST_F(SchemaManagerTest, BackwardsCompatibleVersion) {
// Upgrade to version 1 to get the settings table.
SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, 1);
1, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::UpgradeSucceeded, result);

SettingsDAO settings(dbConnection());

// Pretend the database version is one past the required version but
// min_compatible is the required version.
settings.setValue(SchemaManager::SETTINGS_VERSION_STRING,
MixxxDb::kRequiredSchemaVersion + 1);
MixxxDb::kRequiredSchemaVersion + 1);
settings.setValue(SchemaManager::SETTINGS_MINCOMPATIBLE_STRING,
MixxxDb::kRequiredSchemaVersion);
MixxxDb::kRequiredSchemaVersion);
}

SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, MixxxDb::kRequiredSchemaVersion);
MixxxDb::kRequiredSchemaVersion, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::NewerVersionBackwardsCompatible, result);
}

Expand All @@ -85,22 +85,22 @@ TEST_F(SchemaManagerTest, BackwardsIncompatibleVersion) {
// Upgrade to version 1 to get the settings table.
SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, 1);
1, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::UpgradeSucceeded, result);

SettingsDAO settings(dbConnection());

// Pretend the database version is one past the required version and
// min_compatible is one past the required version.
settings.setValue(SchemaManager::SETTINGS_VERSION_STRING,
MixxxDb::kRequiredSchemaVersion + 1);
MixxxDb::kRequiredSchemaVersion + 1);
settings.setValue(SchemaManager::SETTINGS_MINCOMPATIBLE_STRING,
MixxxDb::kRequiredSchemaVersion + 1);
MixxxDb::kRequiredSchemaVersion + 1);
}

SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, MixxxDb::kRequiredSchemaVersion);
MixxxDb::kRequiredSchemaVersion, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::NewerVersionIncompatible, result);
}

Expand All @@ -110,18 +110,18 @@ TEST_F(SchemaManagerTest, IgnoreDuplicateColumn) {
// Upgrade to version 3 to get the modern library table.
SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, 3);
3, MixxxDb::kDefaultSchemaFile);
ASSERT_EQ(SchemaManager::Result::UpgradeSucceeded, result);
}

// Add a column that will be added again in version 24.
QSqlQuery query(dbConnection());
ASSERT_TRUE(query.exec(
"ALTER TABLE library ADD COLUMN coverart_source TEXT"));
ASSERT_TRUE(
query.exec("ALTER TABLE library ADD COLUMN coverart_source TEXT"));

SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, MixxxDb::kRequiredSchemaVersion);
MixxxDb::kRequiredSchemaVersion, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::UpgradeSucceeded, result);
}

Expand All @@ -131,17 +131,16 @@ TEST_F(SchemaManagerTest, UpgradeFailed) {
// Upgrade to version 3 to get the modern library table.
SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, 3);
3, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::UpgradeSucceeded, result);
}

// Drop a table that is expected to exist.
QSqlQuery query(dbConnection());
EXPECT_TRUE(query.exec(
"DROP TABLE PlaylistTracks"));
EXPECT_TRUE(query.exec("DROP TABLE PlaylistTracks"));

SchemaManager schemaManager(dbConnection());
SchemaManager::Result result = schemaManager.upgradeToSchemaVersion(
MixxxDb::kDefaultSchemaFile, MixxxDb::kRequiredSchemaVersion);
MixxxDb::kRequiredSchemaVersion, MixxxDb::kDefaultSchemaFile);
EXPECT_EQ(SchemaManager::Result::UpgradeFailed, result);
}
7 changes: 1 addition & 6 deletions src/track/trackid.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef TRACKID_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid to include unrelated changes in future PRs.

#define TRACKID_H

#pragma once

#include "util/db/dbid.h"


class TrackId: public DbId {
public:
// Inherit constructors from base class
Expand All @@ -15,5 +12,3 @@ Q_DECLARE_TYPEINFO(TrackId, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(TrackId)

typedef QList<TrackId> TrackIdList;

#endif // TRACKID_H
8 changes: 1 addition & 7 deletions src/util/db/dbconnectionpooler.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef MIXXX_DBCONNECTIONPOOLER_H
#define MIXXX_DBCONNECTIONPOOLER_H

#pragma once

#include "util/db/dbconnectionpool.h"


namespace mixxx {

// Manages the lifetime of a thread-local database connection that is
Expand Down Expand Up @@ -47,6 +44,3 @@ class DbConnectionPooler final {
};

} // namespace mixxx


#endif // MIXXX_DBCONNECTIONPOOLER_H