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

Playlist: Allow duplicated mdeia

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