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

MediaGroup: Add a nb_media field

Which will keep track of all media in this group, regardless of their
presence.
Refs #251
parent b18490b1
......@@ -48,6 +48,7 @@ MediaGroup::MediaGroup( MediaLibraryPtr ml, sqlite::Row& row )
, m_nbVideo( row.extract<decltype(m_nbVideo)>() )
, m_nbAudio( row.extract<decltype(m_nbAudio)>() )
, m_nbUnknown( row.extract<decltype(m_nbUnknown)>() )
, m_nbMedia( row.extract<decltype(m_nbMedia)>() )
, m_duration( row.extract<decltype(m_duration)>() )
, m_creationDate( row.extract<decltype(m_creationDate)>() )
, m_lastModificationDate( row.extract<decltype(m_lastModificationDate)>() )
......@@ -65,6 +66,7 @@ MediaGroup::MediaGroup( MediaLibraryPtr ml, std::string name, bool userInitiated
, m_nbVideo( 0 )
, m_nbAudio( 0 )
, m_nbUnknown( 0 )
, m_nbMedia( 0 )
, m_duration( 0 )
, m_creationDate( time( nullptr ) )
, m_lastModificationDate( m_creationDate )
......@@ -80,6 +82,7 @@ MediaGroup::MediaGroup( MediaLibraryPtr ml , std::string name )
, m_nbVideo( 0 )
, m_nbAudio( 0 )
, m_nbUnknown( 0 )
, m_nbMedia( 0 )
, m_duration( 0 )
, m_creationDate( time( nullptr ) )
, m_lastModificationDate( m_creationDate )
......@@ -461,13 +464,32 @@ std::string MediaGroup::schema( const std::string& name, uint32_t dbModel )
"UNIQUE(parent_id, name) ON CONFLICT FAIL"
")";
}
if ( dbModel == 25 )
{
return "CREATE TABLE " + Table::Name +
"("
"id_group INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT COLLATE NOCASE,"
"nb_video UNSIGNED INTEGER DEFAULT 0,"
"nb_audio UNSIGNED INTEGER DEFAULT 0,"
"nb_unknown UNSIGNED INTEGER DEFAULT 0,"
"duration INTEGER DEFAULT 0,"
"creation_date INTEGER NOT NULL,"
"last_modification_date INTEGER NOT NULL,"
"user_interacted BOOLEAN,"
"forced_singleton BOOLEAN"
")";
}
return "CREATE TABLE " + Table::Name +
"("
"id_group INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT COLLATE NOCASE,"
// Nb media per type, accounting for their presence.
"nb_video UNSIGNED INTEGER DEFAULT 0,"
"nb_audio UNSIGNED INTEGER DEFAULT 0,"
"nb_unknown UNSIGNED INTEGER DEFAULT 0,"
// Total number of media, regardless of presence
"nb_media UNSIGNED INTEGER DEFAULT 0,"
"duration INTEGER DEFAULT 0,"
"creation_date INTEGER NOT NULL,"
"last_modification_date INTEGER NOT NULL,"
......
......@@ -143,6 +143,7 @@ private:
uint32_t m_nbVideo;
uint32_t m_nbAudio;
uint32_t m_nbUnknown;
uint32_t m_nbMedia;
int64_t m_duration;
time_t m_creationDate;
time_t m_lastModificationDate;
......
......@@ -29,11 +29,51 @@ Show::schema( Show::FtsTable::Name, 26 ),
Show::trigger( Show::Triggers::InsertFts, 26 ),
Show::trigger( Show::Triggers::DeleteFts, 26 ),
/* Migrate MediaGroup table */
"CREATE TEMPORARY TABLE " + MediaGroup::Table::Name + "_backup "
"("
"id_group INTEGER PRIMARY KEY,"
"name TEXT COLLATE NOCASE,"
"nb_video UNSIGNED INTEGER DEFAULT 0,"
"nb_audio UNSIGNED INTEGER DEFAULT 0,"
"nb_unknown UNSIGNED INTEGER DEFAULT 0,"
"duration INTEGER DEFAULT 0,"
"creation_date INTEGER,"
"last_modification_date INTEGER,"
"user_interacted BOOLEAN,"
"forced_singleton BOOLEAN"
")",
"INSERT INTO " + MediaGroup::Table::Name + "_backup "
"SELECT * FROM " + MediaGroup::Table::Name,
"DROP TABLE " + MediaGroup::Table::Name,
MediaGroup::schema( MediaGroup::Table::Name, 26 ),
"INSERT INTO " + MediaGroup::Table::Name +
" SELECT id_group, name, nb_video, nb_audio, nb_unknown, "
"(SELECT COUNT(*) FROM " + Media::Table::Name + " m WHERE m.group_id = mg.id_group), "
"duration, creation_date, last_modification_date, user_interacted, forced_singleton "
" FROM " + MediaGroup::Table::Name + "_backup mg",
"DROP TABLE " + MediaGroup::Table::Name + "_backup",
/* Update MediaGroup triggers */
"DROP TRIGGER " + MediaGroup::triggerName( MediaGroup::Triggers::IncrementNbMediaOnGroupChange, 25 ),
"DROP TRIGGER " + MediaGroup::triggerName( MediaGroup::Triggers::DecrementNbMediaOnGroupChange, 25 ),
MediaGroup::trigger( MediaGroup::Triggers::UpdateNbMedia, 26 ),
/* Recreate MediaGroup indexes & triggers that were deleted during the migration */
MediaGroup::trigger( MediaGroup::Triggers::InsertFts, 26 ),
MediaGroup::trigger( MediaGroup::Triggers::DeleteFts, 26 ),
MediaGroup::trigger( MediaGroup::Triggers::DeleteEmptyGroups, 26 ),
MediaGroup::index( MediaGroup::Indexes::ForcedSingleton, 26 ),
MediaGroup::index( MediaGroup::Indexes::Duration, 26 ),
MediaGroup::index( MediaGroup::Indexes::CreationDate, 26 ),
MediaGroup::index( MediaGroup::Indexes::LastModificationDate, 26 ),
/*
* Ensure we don't have restore tasks with no file_type specified. At this point
......
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