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

Artist: Always create an unknown artist & various artists representation

parent 6a1f0728
......@@ -29,6 +29,12 @@
#include "Types.h"
#include "factory/IFileSystem.h"
namespace medialibrary
{
static constexpr auto UnknownArtistID = 1u;
static constexpr auto VariousArtistID = 2u;
}
class IMediaLibraryCb
{
public:
......
......@@ -174,6 +174,16 @@ bool Artist::createTable( DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, reqRel );
}
bool Artist::createDefaultArtists( DBConnection dbConnection )
{
// Don't rely on Artist::create, since we want to insert or do nothing here.
// This will skip the cache for those new entities, but they will be inserted soon enough anyway.
static const std::string req = "INSERT OR IGNORE INTO " + policy::ArtistTable::Name +
"(id_artist) VALUES(?),(?)";
return sqlite::Tools::executeRequest( dbConnection, req, medialibrary::UnknownArtistID,
medialibrary::VariousArtistID );
}
std::shared_ptr<Artist> Artist::create( DBConnection dbConnection, const std::string &name )
{
auto artist = std::make_shared<Artist>( name );
......
......@@ -65,6 +65,7 @@ public:
bool markAsAlbumArtist();
static bool createTable( DBConnection dbConnection );
static bool createDefaultArtists( DBConnection dbConnection );
static std::shared_ptr<Artist> create( DBConnection dbConnection, const std::string& name );
private:
......
......@@ -151,7 +151,8 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& sna
Movie::createTable( m_dbConnection.get() ) &&
VideoTrack::createTable( m_dbConnection.get() ) &&
AudioTrack::createTable( m_dbConnection.get() ) &&
Artist::createTable( m_dbConnection.get() ) ) )
Artist::createTable( m_dbConnection.get() ) &&
Artist::createDefaultArtists( m_dbConnection.get() ) ) )
{
LOG_ERROR( "Failed to create database structure" );
return false;
......
......@@ -44,6 +44,16 @@ TEST_F( Artists, Create )
ASSERT_EQ( a2->name(), "Flying Otters" );
}
TEST_F( Artists, CreateDefaults )
{
// Ensure this won't fail due to duplicate insertions
// We just reload, which will call the initialization routine again.
// This is implicitely tested by all other tests, though it seems better
// to have an explicit one. We might also just run the request twice from here
// sometime in the future.
Reload();
}
TEST_F( Artists, ShortBio )
{
auto a = ml->createArtist( "Raging Otters" );
......
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