mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-18 19:50:38 +01:00
Automatically remove devices with old schemas when upgrading
This commit is contained in:
parent
43b9941dc8
commit
2d3f41da6f
@ -75,4 +75,4 @@ CREATE VIRTUAL TABLE device_%deviceid_fts USING fts5(
|
||||
tokenize = "unicode61 remove_diacritics 0"
|
||||
);
|
||||
|
||||
UPDATE devices SET schema_version=0 WHERE ROWID=%deviceid;
|
||||
UPDATE devices SET schema_version=1 WHERE ROWID=%deviceid;
|
||||
|
@ -147,7 +147,10 @@ QSqlDatabase Database::Connect() {
|
||||
UpdateDatabaseSchema(0, db);
|
||||
}
|
||||
|
||||
else if (SchemaVersion(&db) <= 8) { // Register unicode from unicode61 tokenizer to drop old FTS3 tables.
|
||||
{
|
||||
// Register unicode from unicode61 tokenizer to drop old FTS3 tables.
|
||||
// We need it also to drop old devices later when loading devices.
|
||||
// And that's done in a different thread after schemas are upgraded, so register it anyway.
|
||||
#ifdef SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
|
||||
QVariant v = db.driver()->handle();
|
||||
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "core/logging.h"
|
||||
#include "devicedatabasebackend.h"
|
||||
|
||||
const int DeviceDatabaseBackend::kDeviceSchemaVersion = 0;
|
||||
const int DeviceDatabaseBackend::kDeviceSchemaVersion = 1;
|
||||
|
||||
DeviceDatabaseBackend::DeviceDatabaseBackend(QObject *parent) :
|
||||
QObject(parent),
|
||||
@ -81,12 +81,13 @@ void DeviceDatabaseBackend::Exit() {
|
||||
DeviceDatabaseBackend::DeviceList DeviceDatabaseBackend::GetAllDevices() {
|
||||
|
||||
DeviceList ret;
|
||||
DeviceList old_devices;
|
||||
|
||||
{
|
||||
QMutexLocker l(db_->Mutex());
|
||||
QSqlDatabase db(db_->Connect());
|
||||
QSqlQuery q(db);
|
||||
q.prepare("SELECT ROWID, unique_id, friendly_name, size, icon, transcode_mode, transcode_format FROM devices");
|
||||
q.prepare("SELECT ROWID, unique_id, friendly_name, size, icon, schema_version, transcode_mode, transcode_format FROM devices");
|
||||
q.exec();
|
||||
if (db_->CheckErrors(q)) return ret;
|
||||
|
||||
@ -97,12 +98,22 @@ DeviceDatabaseBackend::DeviceList DeviceDatabaseBackend::GetAllDevices() {
|
||||
dev.friendly_name_ = q.value(2).toString();
|
||||
dev.size_ = q.value(3).toLongLong();
|
||||
dev.icon_name_ = q.value(4).toString();
|
||||
dev.transcode_mode_ = MusicStorage::TranscodeMode(q.value(5).toInt());
|
||||
dev.transcode_format_ = Song::FileType(q.value(6).toInt());
|
||||
ret << dev;
|
||||
int schema_version = q.value(5).toInt();
|
||||
dev.transcode_mode_ = MusicStorage::TranscodeMode(q.value(6).toInt());
|
||||
dev.transcode_format_ = Song::FileType(q.value(7).toInt());
|
||||
if (schema_version < kDeviceSchemaVersion) { // Device is using old schema, drop it.
|
||||
old_devices << dev;
|
||||
}
|
||||
else {
|
||||
ret << dev;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Device dev : old_devices) {
|
||||
RemoveDevice(dev.id_);
|
||||
}
|
||||
|
||||
Close();
|
||||
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user