Commit acb6c62b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

MediaLibrary: Fixup a defective trigger during 12 to 13 migration

parent 99a12d8c
...@@ -152,7 +152,7 @@ std::vector<MediaPtr> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId ...@@ -152,7 +152,7 @@ std::vector<MediaPtr> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId
{ {
std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m" std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m"
" INNER JOIN " + policy::AlbumTrackTable::Name + " t ON m.id_media = t.media_id" " INNER JOIN " + policy::AlbumTrackTable::Name + " t ON m.id_media = t.media_id"
" WHERE t.genre_id = ? ORDER BY "; " WHERE t.genre_id = ? AND m.is_present = 1 ORDER BY ";
switch ( sort ) switch ( sort )
{ {
case SortingCriteria::Duration: case SortingCriteria::Duration:
......
...@@ -1018,6 +1018,7 @@ void MediaLibrary::migrateModel10to11() ...@@ -1018,6 +1018,7 @@ void MediaLibrary::migrateModel10to11()
void MediaLibrary::migrateModel12to13() void MediaLibrary::migrateModel12to13()
{ {
{
sqlite::Connection::WeakDbContext weakConnCtx{ getConn() }; sqlite::Connection::WeakDbContext weakConnCtx{ getConn() };
auto t = getConn()->newTransaction(); auto t = getConn()->newTransaction();
using namespace policy; using namespace policy;
...@@ -1032,6 +1033,13 @@ void MediaLibrary::migrateModel12to13() ...@@ -1032,6 +1033,13 @@ void MediaLibrary::migrateModel12to13()
// Also fix a trigger that was wrongly created & deleted during this migration // Also fix a trigger that was wrongly created & deleted during this migration
AlbumTrack::createTriggers( getConn() ); AlbumTrack::createTriggers( getConn() );
t->commit(); t->commit();
}
// Leave the weak context as we now need to update is_present fields, which
// are propagated through recursive triggers
const std::string req = "UPDATE " + policy::AlbumTrackTable::Name +
" SET is_present = (SELECT is_present FROM " + policy::MediaTable::Name +
" WHERE id_media = media_id)";
sqlite::Tools::executeUpdate( getConn(), req );
} }
void MediaLibrary::reload() void MediaLibrary::reload()
......
...@@ -167,4 +167,8 @@ TEST_F( DbModel, Upgrade12to13 ) ...@@ -167,4 +167,8 @@ TEST_F( DbModel, Upgrade12to13 )
m = media[1]; m = media[1];
ASSERT_EQ( m->thumbnail(), "" ); ASSERT_EQ( m->thumbnail(), "" );
ASSERT_FALSE( m->isThumbnailGenerated() ); ASSERT_FALSE( m->isThumbnailGenerated() );
// Check that we also recovered from the invalid album track trigger
auto albums = ml->albums( SortingCriteria::Default, false );
ASSERT_EQ( 1u, albums.size() );
} }
Supports Markdown
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