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

MediaLibrary: Add missing bits to the model 12 to 13 migration

parent 3c0e6f1f
......@@ -1009,12 +1009,33 @@ void MediaLibrary::migrateModel10to11()
t->commit();
}
/*
* - Some is_present related triggers were fixed in model 6 to 7 migration, but
* they were not recreated if already existing. The has_file_present trigger
* was recreated as part of model 7 to 8 migration, but we need to ensure
* has_album_present (Artist) & is_album_present (Album) triggers are
* recreated to behave as expected
* - Due to a typo, is_track_present was named is_track_presentAFTER, and was
* executed BEFORE the update took place, thus using the wrong is_present value.
* The trigger will be recreated as part of this migration, and the values
* will be enforced, causing the entire update chain to be triggered, and
* restoring correct is_present values for all AlbumTrack/Album/Artist entries
*/
void MediaLibrary::migrateModel12to13()
{
auto t = getConn()->newTransaction();
const std::string req = "DROP TRIGGER IF EXISTS is_track_presentAFTER";
sqlite::Tools::executeDelete( getConn(), req );
const std::string reqs[] = {
"DROP TRIGGER IF EXISTS is_track_presentAFTER",
"DROP TRIGGER has_album_present",
"DROP TRIGGER is_album_present",
};
for ( const auto& req : reqs )
sqlite::Tools::executeDelete( getConn(), req );
AlbumTrack::createTriggers( getConn() );
Album::createTriggers( getConn() );
Artist::createTriggers( getConn(), 13 );
// Leave the weak context as we now need to update is_present fields, which
// are propagated through recursive triggers
const std::string migrateData = "UPDATE " + policy::AlbumTrackTable::Name +
......
......@@ -168,7 +168,10 @@ TEST_F( DbModel, Upgrade12to13 )
LoadFakeDB( SRC_DIR "/test/unittest/db_v12.sql" );
auto res = ml->initialize( "test.db", "/tmp", cbMock.get() );
ASSERT_EQ( InitializeResult::Success, res );
// Check that we also recovered from the invalid album track trigger
auto albums = ml->albums( SortingCriteria::Default, false );
ASSERT_EQ( 1u, albums.size() );
CheckNbTriggers( 31 );
}
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