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

Bump model to v15

(cherry picked from commit e98cd2bb)
Signed-off-by: 's avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent a59352d8
Pipeline #3877 passed with stages
in 12 minutes and 31 seconds
......@@ -906,6 +906,11 @@ InitializeResult MediaLibrary::updateDatabaseModel( unsigned int previousVersion
migrateModel13to14( originalPreviousVersion );
previousVersion = 14;
}
if ( previousVersion == 14 )
{
migrateModel14to15();
previousVersion = 15;
}
// To be continued in the future!
if ( needRescan == true )
......@@ -1235,6 +1240,26 @@ void MediaLibrary::migrateModel13to14( uint32_t originalPreviousVersion )
t->commit();
}
/**
* Model 14 to 15 migration:
* - Folder.name is now case insensitive
* - New chapters table
*/
void MediaLibrary::migrateModel14to15()
{
auto dbConn = getConn();
sqlite::Connection::WeakDbContext weakConnCtx{ dbConn };
auto t = dbConn->newTransaction();
std::string reqs[] = {
# include "database/migrations/migration14-15.sql"
};
for ( const auto& req : reqs )
sqlite::Tools::executeRequest( dbConn, req );
Folder::createTriggers( dbConn, 15 );
t->commit();
}
void MediaLibrary::reload()
{
if ( m_discovererWorker != nullptr )
......
......@@ -216,6 +216,7 @@ private:
void migrateModel10to11();
void migrateModel12to13();
void migrateModel13to14( uint32_t originalPreviousVersion );
void migrateModel14to15();
void createAllTables();
void createAllTriggers();
void registerEntityHooks();
......
......@@ -32,7 +32,7 @@
namespace medialibrary
{
const uint32_t Settings::DbModelVersion = 14u;
const uint32_t Settings::DbModelVersion = 15u;
Settings::Settings( MediaLibrary* ml )
: m_ml( ml )
......
/******************* Migrate Folder table *************************************/
"CREATE TEMPORARY TABLE " + Folder::Table::Name + "_backup"
"("
"id_folder INTEGER PRIMARY KEY AUTOINCREMENT,"
"path TEXT,"
"name TEXT,"
"parent_id UNSIGNED INTEGER,"
"is_banned BOOLEAN NOT NULL DEFAULT 0,"
"device_id UNSIGNED INTEGER,"
"is_removable BOOLEAN NOT NULL,"
"nb_audio UNSIGNED INTEGER NOT NULL DEFAULT 0,"
"nb_video UNSIGNED INTEGER NOT NULL DEFAULT 0"
")",
"INSERT INTO " + Folder::Table::Name + "_backup SELECT * FROM " + Folder::Table::Name,
"DROP TABLE " + Folder::Table::Name,
#include "database/tables/Folder_v15.sql"
"INSERT INTO " + Folder::Table::Name + "("
"id_folder, path, name, parent_id, is_banned, device_id, is_removable,"
"nb_audio, nb_video"
") "
"SELECT id_folder, path, name, parent_id, is_banned, device_id, is_removable,"
"nb_audio, nb_video "
"FROM " + Folder::Table::Name + "_backup",
"DROP TABLE " + Folder::Table::Name + "_backup",
......@@ -233,3 +233,11 @@ TEST_F( DbModel, Upgrade13to14 )
CheckNbTriggers( 35 );
}
TEST_F( DbModel, Upgrade14to15 )
{
LoadFakeDB( SRC_DIR "/test/unittest/db_v14.sql" );
auto res = ml->initialize( "test.db", "/tmp", cbMock.get() );
ASSERT_EQ( InitializeResult::Success, res );
CheckNbTriggers( 35 );
}
This diff is collapsed.
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