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

Playlist: Index file_id

parent d5ed4951
......@@ -143,6 +143,7 @@ void MediaLibrary::clearCache()
void MediaLibrary::createAllTables()
{
auto dbModelVersion = m_settings.dbModelVersion();
// We need to create the tables in order of triggers creation
// Device is the "root of all evil". When a device is modified,
// we will trigger an update on folder, which will trigger
......@@ -154,7 +155,7 @@ void MediaLibrary::createAllTables()
Media::createTable( m_dbConnection.get() );
File::createTable( m_dbConnection.get() );
Label::createTable( m_dbConnection.get() );
Playlist::createTable( m_dbConnection.get() );
Playlist::createTable( m_dbConnection.get(), dbModelVersion );
Genre::createTable( m_dbConnection.get() );
Album::createTable( m_dbConnection.get() );
AlbumTrack::createTable( m_dbConnection.get() );
......
......@@ -251,13 +251,20 @@ bool Playlist::remove( int64_t mediaId )
return sqlite::Tools::executeDelete( m_ml->getConn(), req, m_id, mediaId );
}
void Playlist::createTable( sqlite::Connection* dbConn )
void Playlist::createTable( sqlite::Connection* dbConn, uint32_t dbModel )
{
std::string reqs[] = {
#include "database/tables/Playlist_v14.sql"
};
for ( const auto& req : reqs )
sqlite::Tools::executeRequest( dbConn, req );
// Playlist doesn't have an mrl field before version 14, so we must not
// create the trigger before migrating to that version
if ( dbModel >= 14 )
{
sqlite::Tools::executeRequest( dbConn, "CREATE INDEX IF NOT EXISTS "
"playlist_file_id ON " + policy::PlaylistTable::Name + "(file_id)" );
}
}
void Playlist::createTriggers( sqlite::Connection* dbConn )
......
......@@ -69,7 +69,7 @@ public:
std::shared_ptr<File> addFile( const fs::IFile& fileFs, int64_t parentFolderId,
bool isFolderFsRemovable );
static void createTable( sqlite::Connection* dbConn );
static void createTable( sqlite::Connection* dbConn , uint32_t dbModel );
static void createTriggers( sqlite::Connection* dbConn );
static Query<IPlaylist> search( MediaLibraryPtr ml, const std::string& name,
const QueryParameters* params );
......
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