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

File: Split triggers & indices creation in a separate function

parent 9bd24536
......@@ -174,6 +174,12 @@ void File::createTable( sqlite::Connection* dbConnection )
+ "(id_folder) ON DELETE CASCADE,"
"UNIQUE( mrl, folder_id ) ON CONFLICT FAIL"
")";
sqlite::Tools::executeRequest( dbConnection, req );
}
void File::createTriggers(sqlite::Connection* dbConnection)
{
std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS is_folder_present AFTER UPDATE OF is_present ON "
+ policy::FolderTable::Name +
" BEGIN"
......@@ -183,7 +189,6 @@ void File::createTable( sqlite::Connection* dbConnection )
policy::FileTable::Name + "(media_id)";
std::string folderIndexReq = "CREATE INDEX IF NOT EXISTS file_folder_id_index ON " +
policy::FileTable::Name + "(folder_id)";
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, triggerReq );
sqlite::Tools::executeRequest( dbConnection, mediaIndexReq );
sqlite::Tools::executeRequest( dbConnection, folderIndexReq );
......
......@@ -64,6 +64,7 @@ public:
int64_t folderId();
static void createTable( sqlite::Connection* dbConnection );
static void createTriggers( sqlite::Connection* dbConnection );
static std::shared_ptr<File> createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type,
const fs::IFile& file, int64_t folderId, bool isRemovable );
static std::shared_ptr<File> createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type,
......
......@@ -165,6 +165,7 @@ void MediaLibrary::createAllTriggers()
Album::createTriggers( m_dbConnection.get() );
Artist::createTriggers( m_dbConnection.get(), dbModelVersion );
Media::createTriggers( m_dbConnection.get() );
File::createTriggers( m_dbConnection.get() );
Genre::createTriggers( m_dbConnection.get() );
Playlist::createTriggers( m_dbConnection.get() );
}
......
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