From 4dcc9b602eb9b2d4e030ff46dfbf54fd34d0eda0 Mon Sep 17 00:00:00 2001 From: whatdoineed2do/Ray Date: Sun, 5 Sep 2021 16:36:02 +0100 Subject: [PATCH] [db] add review 'flag' column to files/queue tbls --- src/db.c | 4 ++++ src/db.h | 4 ++++ src/db_init.c | 6 ++++-- src/db_init.h | 2 +- src/db_upgrade.c | 23 +++++++++++++++++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/db.c b/src/db.c index 73a40809..9c3ecd9c 100644 --- a/src/db.c +++ b/src/db.c @@ -227,6 +227,7 @@ static const struct col_type_map mfi_cols_map[] = { "album_artist_sort", mfi_offsetof(album_artist_sort), DB_TYPE_STRING, DB_FIXUP_ALBUM_ARTIST_SORT }, { "composer_sort", mfi_offsetof(composer_sort), DB_TYPE_STRING, DB_FIXUP_COMPOSER_SORT }, { "channels", mfi_offsetof(channels), DB_TYPE_INT }, + { "flag", mfi_offsetof(flag), DB_TYPE_INT }, }; /* This list must be kept in sync with @@ -294,6 +295,7 @@ static const struct col_type_map qi_cols_map[] = { "bitrate", qi_offsetof(bitrate), DB_TYPE_INT }, { "samplerate", qi_offsetof(samplerate), DB_TYPE_INT }, { "channels", qi_offsetof(channels), DB_TYPE_INT }, + { "flag", qi_offsetof(flag), DB_TYPE_INT }, }; /* This list must be kept in sync with @@ -365,6 +367,7 @@ static const ssize_t dbmfi_cols_map[] = dbmfi_offsetof(album_artist_sort), dbmfi_offsetof(composer_sort), dbmfi_offsetof(channels), + dbmfi_offsetof(flag), }; /* This list must be kept in sync with @@ -453,6 +456,7 @@ static const struct qi_mfi_map qi_mfi_map[] = { qi_offsetof(bitrate), mfi_offsetof(bitrate), dbmfi_offsetof(bitrate) }, { qi_offsetof(samplerate), mfi_offsetof(samplerate), dbmfi_offsetof(samplerate) }, { qi_offsetof(channels), mfi_offsetof(channels), dbmfi_offsetof(channels) }, + { qi_offsetof(flag), mfi_offsetof(flag), dbmfi_offsetof(flag) }, }; /* This list must be kept in sync with diff --git a/src/db.h b/src/db.h index f23f3097..97ca3f58 100644 --- a/src/db.h +++ b/src/db.h @@ -198,6 +198,7 @@ struct media_file_info { uint32_t time_skipped; int64_t disabled; // Long because it stores up to INOTIFY_FAKE_COOKIE + uint32_t flag; uint64_t sample_count; //TODO [unused] sample count is never set and therefor always 0 char *codectype; /* song.codectype, 4 chars max (32 bits) */ @@ -393,6 +394,7 @@ struct db_media_file_info { char *album_artist_sort; char *composer_sort; char *channels; + char *flag; }; #define dbmfi_offsetof(field) offsetof(struct db_media_file_info, field) @@ -502,6 +504,8 @@ struct db_queue_item { int64_t songartistid; + uint32_t flag; + /* Not saved in queue table */ uint32_t seek; }; diff --git a/src/db_init.c b/src/db_init.c index 5e358c7a..99db3163 100644 --- a/src/db_init.c +++ b/src/db_init.c @@ -96,7 +96,8 @@ " album_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \ " album_artist_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \ " composer_sort VARCHAR(1024) DEFAULT NULL COLLATE DAAP," \ - " channels INTEGER DEFAULT 0" \ + " channels INTEGER DEFAULT 0," \ + " flag INTEGER DEFAULT 0" \ ");" #define T_PL \ @@ -199,7 +200,8 @@ " type VARCHAR(8) DEFAULT NULL," \ " bitrate INTEGER DEFAULT 0," \ " samplerate INTEGER DEFAULT 0," \ - " channels INTEGER DEFAULT 0" \ + " channels INTEGER DEFAULT 0," \ + " flag INTEGER DEFAULT 0" \ ");" #define Q_PL1 \ diff --git a/src/db_init.h b/src/db_init.h index 5a12b602..f196770b 100644 --- a/src/db_init.h +++ b/src/db_init.h @@ -26,7 +26,7 @@ * is a major upgrade. In other words minor version upgrades permit downgrading * the server after the database was upgraded. */ #define SCHEMA_VERSION_MAJOR 21 -#define SCHEMA_VERSION_MINOR 06 +#define SCHEMA_VERSION_MINOR 07 int db_init_indices(sqlite3 *hdl); diff --git a/src/db_upgrade.c b/src/db_upgrade.c index efd4c87d..9f05fd8a 100644 --- a/src/db_upgrade.c +++ b/src/db_upgrade.c @@ -1160,6 +1160,22 @@ static const struct db_upgrade_query db_upgrade_v2106_queries[] = { U_v2106_SCVER_MINOR, "set schema_version_minor to 06" }, }; +/* ---------------------------- 21.06 -> 21.07 ------------------------------ */ +#define U_v2107_ALTER_FILES_PENDING_DELETE \ + "ALTER TABLE files ADD COLUMN flag INTEGER DEFAULT 0;" +#define U_v2107_ALTER_QUEUE_PENDING_DELETE \ + "ALTER TABLE queue ADD COLUMN flag INTEGER DEFAULT 0;" +#define U_v2107_SCVER_MINOR \ + "UPDATE admin SET value = '07' WHERE key = 'schema_version_minor';" + +static const struct db_upgrade_query db_upgrade_v2107_queries[] = + { + { U_v2107_ALTER_FILES_PENDING_DELETE, "update files adding flag" }, + { U_v2107_ALTER_QUEUE_PENDING_DELETE, "update queue adding flag" }, + + { U_v2107_SCVER_MINOR, "set schema_version_minor to 07" }, + }; + /* -------------------------- Main upgrade handler -------------------------- */ @@ -1357,6 +1373,13 @@ db_upgrade(sqlite3 *hdl, int db_ver) if (ret < 0) return -1; + /* FALLTHROUGH */ + + case 2106: + ret = db_generic_upgrade(hdl, db_upgrade_v2107_queries, ARRAY_SIZE(db_upgrade_v2107_queries)); + if (ret < 0) + return -1; + /* Last case statement is the only one that ends with a break statement! */ break;