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

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
{
std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m"
" 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 )
{
case SortingCriteria::Duration:
......
......@@ -1018,6 +1018,7 @@ void MediaLibrary::migrateModel10to11()
void MediaLibrary::migrateModel12to13()
{
{
sqlite::Connection::WeakDbContext weakConnCtx{ getConn() };
auto t = getConn()->newTransaction();
using namespace policy;
......@@ -1032,6 +1033,13 @@ void MediaLibrary::migrateModel12to13()
// Also fix a trigger that was wrongly created & deleted during this migration
AlbumTrack::createTriggers( getConn() );
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()
......
......@@ -167,4 +167,8 @@ TEST_F( DbModel, Upgrade12to13 )
m = media[1];
ASSERT_EQ( m->thumbnail(), "" );
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() );
}
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