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

migrations: Use enum_to_string

parent c52cf069
......@@ -69,6 +69,7 @@
#include "utils/TitleAnalyzer.h"
#include "Bookmark.h"
#include "MediaGroup.h"
#include "utils/Enums.h"
// Discoverers:
#include "discoverer/FsDiscoverer.h"
......
......@@ -114,9 +114,7 @@ Media::schema( Media::Table::Name, 25 ),
Bookmark::schema( Bookmark::Table::Name, 25 ),
"INSERT INTO " + Bookmark::Table::Name +
" SELECT *, 0, " +
std::to_string( static_cast<std::underlying_type_t<IBookmark::Type>>(
IBookmark::Type::Simple ) ) +
" SELECT *, 0, " + utils::enum_to_string( IBookmark::Type::Simple ) +
" FROM " + Bookmark::Table::Name + "_backup",
"CREATE TEMPORARY TABLE " + Device::Table::Name + "_backup"
......
......@@ -55,8 +55,7 @@ MediaGroup::schema( MediaGroup::Table::Name, 26 ),
#define COUNT_MEDIA(type) \
" (SELECT COUNT(*) FROM " + Media::Table::Name + " m" \
" WHERE m.group_id = mg.id_group AND m.is_present != 0 AND " \
" m.type = " + std::to_string( \
static_cast<std::underlying_type_t<IMedia::Type>>( type ) ) + "), "
" m.type = " + utils::enum_to_string( ( type ) ) + "), "
"INSERT INTO " + MediaGroup::Table::Name +
" SELECT id_group, name,"
......@@ -97,14 +96,9 @@ MediaGroup::index( MediaGroup::Indexes::LastModificationDate, 26 ),
* tasks.
*/
"UPDATE " + parser::Task::Table::Name + " SET file_type = " +
std::to_string( static_cast<std::underlying_type_t<IFile::Type>>(
IFile::Type::Playlist ) ) +
" WHERE type = " +
std::to_string( static_cast<std::underlying_type_t<parser::Task::Type>>(
parser::Task::Type::Restore ) ) +
" AND file_type = " +
std::to_string( static_cast<std::underlying_type_t<IFile::Type>>(
IFile::Type::Unknown ) ),
utils::enum_to_string( IFile::Type::Playlist ) +
" WHERE type = " + utils::enum_to_string( parser::Task::Type::Restore ) +
" AND file_type = " + utils::enum_to_string( IFile::Type::Unknown ),
/*
* Fix external files is_network state
......
......@@ -77,8 +77,7 @@ MediaGroup::trigger( MediaGroup::Triggers::UpdateDurationOnMediaDeletion, 27 ),
" FROM " + Metadata::Table::Name + " md "
" WHERE entity_type = " +
std::to_string(static_cast<std::underlying_type_t<IMetadata::EntityType>>(
IMetadata::EntityType::Media ) ) +
utils::enum_to_string( IMetadata::EntityType::Media ) +
" AND type = 50 AND md.id_media = m.id_media "
")"
#ifdef __ANDROID__
......
......@@ -64,14 +64,11 @@ MediaGroup::schema( MediaGroup::Table::Name, 30 ),
"INSERT INTO " + MediaGroup::Table::Name +
" SELECT id_group, name, "
" (SELECT COUNT() FROM " + Media::Table::Name + " WHERE group_id = id_group"
" AND type = " + std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Video ) ) + "),"
" AND type = " + utils::enum_to_string( IMedia::Type::Video ) + "),"
" (SELECT COUNT() FROM " + Media::Table::Name + " WHERE group_id = id_group"
" AND type = " + std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Audio ) ) + "),"
" AND type = " + utils::enum_to_string( IMedia::Type::Audio ) + "),"
" (SELECT COUNT() FROM " + Media::Table::Name + " WHERE group_id = id_group"
" AND type = " + std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Unknown) ) + "),"
" AND type = " + utils::enum_to_string( IMedia::Type::Unknown ) + "),"
" nb_video, nb_audio, nb_unknown, duration, creation_date,"
" last_modification_date, user_interacted, forced_singleton "
" FROM " + MediaGroup::Table::Name + "_backup",
......
......@@ -35,41 +35,34 @@ MediaGroup::schema( MediaGroup::Table::Name, 31 ),
"UPDATE " + MediaGroup::Table::Name + " SET "
"nb_video = nb_video - (CASE MQ.type WHEN " +
std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Video ) ) +
utils::enum_to_string( IMedia::Type::Video ) +
" THEN 1 ELSE 0 END),"
"nb_present_video = nb_present_video - "
"(CASE MQ.is_present WHEN 0 THEN 0 ELSE "
"(CASE MQ.type WHEN " +
std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Video ) ) +
utils::enum_to_string( IMedia::Type::Video ) +
" THEN 1 ELSE 0 END)"
"END),"
"nb_audio = nb_audio - (CASE MQ.type WHEN " +
std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Audio ) ) +
utils::enum_to_string( IMedia::Type::Audio ) +
" THEN 1 ELSE 0 END),"
"nb_present_audio = nb_present_audio - "
"(CASE MQ.is_present WHEN 0 THEN 0 ELSE "
"(CASE MQ.type WHEN " +
std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Audio ) ) +
utils::enum_to_string( IMedia::Type::Audio ) +
" THEN 1 ELSE 0 END)"
"END),"
"nb_unknown = nb_unknown - (CASE MQ.type WHEN " +
std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Unknown ) ) +
utils::enum_to_string( IMedia::Type::Unknown ) +
" THEN 1 ELSE 0 END),"
"nb_present_unknown = nb_present_unknown - "
"(CASE MQ.is_present WHEN 0 THEN 0 ELSE "
"(CASE MQ.type WHEN " +
std::to_string( static_cast<std::underlying_type_t<IMedia::Type>>(
IMedia::Type::Unknown ) ) +
utils::enum_to_string( IMedia::Type::Unknown ) +
" THEN 1 ELSE 0 END)"
"END) "
"FROM (SELECT * FROM " + Media::Table::Name + " WHERE import_type = "
+ std::to_string( static_cast<std::underlying_type_t<Media::ImportType>>(
Media::ImportType::External ) ) + ") as MQ "
+ utils::enum_to_string( Media::ImportType::External ) + ") as MQ "
"WHERE MQ.group_id = id_group",
"CREATE TEMPORARY TABLE " + Media::Table::Name + "_backup"
......@@ -164,9 +157,7 @@ MediaGroup::index( MediaGroup::Indexes::LastModificationDate, 31 ),
"UPDATE " + Media::Table::Name + " AS m"
" SET play_count = meta.number"
" FROM (SELECT id_media, CAST(value AS decimal) AS number FROM " + Metadata::Table::Name +
" WHERE entity_type = " + std::to_string(
static_cast<std::underlying_type_t<IMetadata::EntityType>>(
IMetadata::EntityType::Media ) ) +
" WHERE entity_type = " + utils::enum_to_string( IMetadata::EntityType::Media ) +
" AND type = 55"
/* std::to_string( static_cast<std::underlying_type_t<IMedia::MetadataType>>(
IMedia::MetadataType::Seen ) ) */
......
Supports Markdown
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