Introduced the artwork table. Now resolve the preferred release artwork during scan steps
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free 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.
|
||||
*
|
||||
* LMS 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 LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "database/Artwork.hpp"
|
||||
|
||||
#include "database/Image.hpp"
|
||||
#include "database/Session.hpp"
|
||||
#include "database/TrackEmbeddedImage.hpp"
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "traits/IdTypeTraits.hpp"
|
||||
|
||||
namespace lms::db
|
||||
{
|
||||
Artwork::Artwork(ObjectPtr<TrackEmbeddedImage> trackEmbeddedImage)
|
||||
: _trackEmbeddedImage{ getDboPtr(trackEmbeddedImage) }
|
||||
{
|
||||
}
|
||||
|
||||
Artwork::Artwork(ObjectPtr<Image> image)
|
||||
: _image{ getDboPtr(image) }
|
||||
{
|
||||
}
|
||||
|
||||
Artwork::pointer Artwork::create(Session& session, ObjectPtr<TrackEmbeddedImage> trackEmbeddedImage)
|
||||
{
|
||||
session.checkWriteTransaction();
|
||||
return session.getDboSession()->add(std::unique_ptr<Artwork>{ new Artwork{ trackEmbeddedImage } });
|
||||
}
|
||||
|
||||
Artwork::pointer Artwork::create(Session& session, ObjectPtr<Image> image)
|
||||
{
|
||||
session.checkWriteTransaction();
|
||||
return session.getDboSession()->add(std::unique_ptr<Artwork>{ new Artwork{ image } });
|
||||
}
|
||||
|
||||
std::size_t Artwork::getCount(Session& session)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->query<long>("SELECT COUNT(*) FROM artwork"));
|
||||
}
|
||||
|
||||
Artwork::pointer Artwork::find(Session& session, ArtworkId id)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Artwork>>("SELECT a FROM artwork a").where("a.id = ?").bind(id));
|
||||
}
|
||||
|
||||
Artwork::pointer Artwork::find(Session& session, TrackEmbeddedImageId id)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Artwork>>("SELECT a FROM artwork a JOIN track_embedded_image t_e_i ON a.track_embedded_image_id = t_e_i.id").where("t_e_i.id = ?").bind(id));
|
||||
}
|
||||
|
||||
Artwork::pointer Artwork::find(Session& session, ImageId id)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Artwork>>("SELECT a FROM artwork a JOIN image i ON a.image_id = i.id").where("i.id = ?").bind(id));
|
||||
}
|
||||
|
||||
} // namespace lms::db
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/Directory.hpp"
|
||||
#include "database/Release.hpp"
|
||||
#include "database/Session.hpp"
|
||||
|
||||
#include "Utils.hpp"
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace lms::db
|
||||
{
|
||||
namespace
|
||||
{
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 92 };
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 93 };
|
||||
}
|
||||
|
||||
VersionInfo::VersionInfo()
|
||||
@@ -411,7 +411,7 @@ SELECT
|
||||
copyright_url,
|
||||
track_replay_gain,
|
||||
release_replay_gain,
|
||||
COALESCE(artist_display_name, ""),
|
||||
artist_display_name,
|
||||
release_id,
|
||||
1
|
||||
FROM track)");
|
||||
@@ -1219,6 +1219,58 @@ FROM tracklist)");
|
||||
utils::executeCommand(*session.getDboSession(), "ALTER TABLE track_embedded_image_link DROP COLUMN is_preferred");
|
||||
}
|
||||
|
||||
void migrateFromV92(Session& session)
|
||||
{
|
||||
// Create the new artwork table
|
||||
utils::executeCommand(*session.getDboSession(), R"(CREATE TABLE IF NOT EXISTS "artwork" (
|
||||
"id" integer primary key autoincrement,
|
||||
"version" integer not null,
|
||||
"track_embedded_image_id" bigint,
|
||||
"image_id" bigint,
|
||||
constraint "fk_artwork_track_embedded_image" foreign key ("track_embedded_image_id") references "track_embedded_image" ("id") on delete cascade deferrable initially deferred,
|
||||
constraint "fk_artwork_image" foreign key ("image_id") references "image" ("id") on delete cascade deferrable initially deferred))");
|
||||
|
||||
// Replaced image by artwork for release
|
||||
// Create the new table, copy the data, drop the old table, rename the new one
|
||||
utils::executeCommand(*session.getDboSession(), R"(CREATE TABLE IF NOT EXISTS "release_backup" (
|
||||
"id" integer primary key autoincrement,
|
||||
"version" integer not null,
|
||||
"name" text not null,
|
||||
"sort_name" text not null,
|
||||
"mbid" text not null,
|
||||
"group_mbid" text not null,
|
||||
"total_disc" integer,
|
||||
"artist_display_name" text not null,
|
||||
"is_compilation" boolean not null,
|
||||
"barcode" text not null,
|
||||
"comment" text not null,
|
||||
"preferred_artwork_id" bigint,
|
||||
constraint "fk_release_preferred_artwork" foreign key ("preferred_artwork_id") references "artwork" ("id") on delete set null deferrable initially deferred))");
|
||||
|
||||
// Migrate data, with the new preferred_artwork_id field set to null
|
||||
utils::executeCommand(*session.getDboSession(), R"(INSERT INTO release_backup
|
||||
SELECT
|
||||
id,
|
||||
version,
|
||||
name,
|
||||
sort_name,
|
||||
mbid,
|
||||
group_mbid,
|
||||
total_disc,
|
||||
COALESCE(artist_display_name, ''),
|
||||
is_compilation,
|
||||
barcode,
|
||||
comment,
|
||||
NULL as preferred_artwork_id
|
||||
FROM release)");
|
||||
|
||||
utils::executeCommand(*session.getDboSession(), "DROP TABLE release");
|
||||
utils::executeCommand(*session.getDboSession(), "ALTER TABLE release_backup RENAME TO release");
|
||||
|
||||
// Just increment the scan version of the settings to make the next scan rescan everything
|
||||
utils::executeCommand(*session.getDboSession(), "UPDATE scan_settings SET artist_info_scan_version = artist_info_scan_version + 1");
|
||||
}
|
||||
|
||||
bool doDbMigration(Session& session)
|
||||
{
|
||||
constexpr std::string_view outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
|
||||
@@ -1286,7 +1338,8 @@ FROM tracklist)");
|
||||
{ 88, migrateFromV88 },
|
||||
{ 89, migrateFromV89 },
|
||||
{ 90, migrateFromV90 },
|
||||
{ 91, migrateFromV91 }
|
||||
{ 91, migrateFromV91 },
|
||||
{ 92, migrateFromV92 }
|
||||
};
|
||||
|
||||
bool migrationPerformed{};
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
#include "core/PartialDateTime.hpp"
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/Artwork.hpp"
|
||||
#include "database/Cluster.hpp"
|
||||
#include "database/Directory.hpp"
|
||||
#include "database/Image.hpp"
|
||||
#include "database/Session.hpp"
|
||||
#include "database/Track.hpp"
|
||||
#include "database/Types.hpp"
|
||||
@@ -701,14 +701,9 @@ namespace lms::db
|
||||
return utils::fetchQueryResults<Release::pointer>(query);
|
||||
}
|
||||
|
||||
ObjectPtr<Image> Release::getImage() const
|
||||
ObjectPtr<Artwork> Release::getPreferredArtwork() const
|
||||
{
|
||||
return ObjectPtr<Image>{ _image };
|
||||
}
|
||||
|
||||
ImageId Release::getImageId() const
|
||||
{
|
||||
return _image.id();
|
||||
return ObjectPtr<Artwork>{ _preferredArtwork };
|
||||
}
|
||||
|
||||
void Release::clearLabels()
|
||||
@@ -741,9 +736,9 @@ namespace lms::db
|
||||
_releaseTypes.insert(getDboPtr(releaseType));
|
||||
}
|
||||
|
||||
void Release::setImage(ObjectPtr<Image> image)
|
||||
void Release::setPreferredArtwork(ObjectPtr<Artwork> artwork)
|
||||
{
|
||||
_image = getDboPtr(image);
|
||||
_preferredArtwork = getDboPtr(artwork);
|
||||
}
|
||||
|
||||
bool Release::hasVariousArtists() const
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "core/ITraceLogger.hpp"
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/ArtistInfo.hpp"
|
||||
#include "database/Artwork.hpp"
|
||||
#include "database/AuthToken.hpp"
|
||||
#include "database/Cluster.hpp"
|
||||
#include "database/Db.hpp"
|
||||
@@ -102,6 +103,7 @@ namespace lms::db
|
||||
|
||||
_session.mapClass<Artist>("artist");
|
||||
_session.mapClass<ArtistInfo>("artist_info");
|
||||
_session.mapClass<Artwork>("artwork");
|
||||
_session.mapClass<AuthToken>("auth_token");
|
||||
_session.mapClass<Cluster>("cluster");
|
||||
_session.mapClass<ClusterType>("cluster_type");
|
||||
@@ -206,6 +208,10 @@ namespace lms::db
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artist_info_artist_id_idx ON artist_info(artist_id)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artist_info_mbid_matched_artist_idx ON artist_info(mbid_matched, artist_id)");
|
||||
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artwork_id_idx ON artwork(id)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artwork_image_idx ON artwork(image_id)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artwork_track_embedded_image_idx ON artwork(track_embedded_image_id)");
|
||||
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS auth_token_user_domain_idx ON auth_token(user_id, domain)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS auth_token_domain_expiry_idx ON auth_token(domain, expiry)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS auth_token_domain_value_idx ON auth_token(domain, value)");
|
||||
@@ -256,7 +262,6 @@ namespace lms::db
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS rated_track_user_track_idx ON rated_track(user_id,track_id)");
|
||||
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS release_id_idx ON release(id)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS release_image_idx ON release(image_id)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS release_group_mbid_idx ON release(group_mbid)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS release_mbid_idx ON release(mbid)");
|
||||
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS release_name_idx ON release(name)");
|
||||
|
||||
Reference in New Issue
Block a user