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

Playlist: Allow duplicated mdeia

Fix #27
parent 9e0aec06
......@@ -191,12 +191,14 @@ void Playlist::createTable( sqlite::Connection* dbConn )
"media_id INTEGER,"
"playlist_id INTEGER,"
"position INTEGER,"
"PRIMARY KEY(media_id, playlist_id),"
"FOREIGN KEY(media_id) REFERENCES " + policy::MediaTable::Name + "("
+ policy::MediaTable::PrimaryKeyColumn + ") ON DELETE CASCADE,"
"FOREIGN KEY(playlist_id) REFERENCES " + policy::PlaylistTable::Name + "("
+ policy::PlaylistTable::PrimaryKeyColumn + ") ON DELETE CASCADE"
")";
const std::string indexReq = "CREATE INDEX IF NOT EXISTS playlist_media_pl_id_index "
"ON PlaylistMediaRelation(media_id, playlist_id)";
const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
+ policy::PlaylistTable::Name + "Fts USING FTS3("
"name"
......@@ -204,6 +206,7 @@ void Playlist::createTable( sqlite::Connection* dbConn )
//FIXME Enforce (playlist_id,position) uniqueness
sqlite::Tools::executeRequest( dbConn, req );
sqlite::Tools::executeRequest( dbConn, relTableReq );
sqlite::Tools::executeRequest( dbConn, indexReq );
sqlite::Tools::executeRequest( dbConn, vtableReq );
}
......
......@@ -325,7 +325,11 @@ TEST_F( Playlists, AddDuplicate )
auto res = pl->append( m->id() );
ASSERT_TRUE( res );
res = pl->append( m->id() );
ASSERT_FALSE( res );
ASSERT_TRUE( res );
auto media = pl->media()->all();
ASSERT_EQ( 2u, media.size() );
ASSERT_EQ( m->id(), media[0]->id() );
ASSERT_EQ( m->id(), media[1]->id() );
}
TEST_F( Playlists, SearchMedia )
......
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