mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-15 16:53:18 -05:00
Handle database upgrade v7 -> v8
This commit is contained in:
parent
224ef48137
commit
07146e3261
40
src/db.c
40
src/db.c
@ -3526,6 +3526,39 @@ static struct db_init_query db_upgrade_v7_queries[] =
|
|||||||
{ U_V7_SCVER, "set schema_version to 7" },
|
{ U_V7_SCVER, "set schema_version to 7" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Upgrade from schema v7 to v8 */
|
||||||
|
#define U_V8_GROUPS \
|
||||||
|
"CREATE TABLE IF NOT EXISTS groups (" \
|
||||||
|
" id INTEGER PRIMARY KEY NOT NULL," \
|
||||||
|
" type INTEGER NOT NULL," \
|
||||||
|
" name VARCHAR(1024) NOT NULL," \
|
||||||
|
" persistentid INTEGER NOT NULL," \
|
||||||
|
"CONSTRAINT groups_type_unique_persistentid UNIQUE (type, persistentid)" \
|
||||||
|
");"
|
||||||
|
|
||||||
|
#define U_V8_TRG1 \
|
||||||
|
"CREATE TRIGGER update_groups_new_file AFTER INSERT ON files FOR EACH ROW" \
|
||||||
|
" BEGIN" \
|
||||||
|
" INSERT OR IGNORE INTO groups (type, name, persistentid) VALUES (1, NEW.album, NEW.songalbumid);" \
|
||||||
|
" END;"
|
||||||
|
|
||||||
|
#define U_V8_TRG2 \
|
||||||
|
"CREATE TRIGGER update_groups_update_file AFTER UPDATE OF songalbumid ON files FOR EACH ROW" \
|
||||||
|
" BEGIN" \
|
||||||
|
" INSERT OR IGNORE INTO groups (type, name, persistentid) VALUES (1, NEW.album, NEW.songalbumid);" \
|
||||||
|
" END;"
|
||||||
|
|
||||||
|
#define U_V8_SCVER \
|
||||||
|
"UPDATE admin SET value = '8' WHERE key = 'schema_version';"
|
||||||
|
|
||||||
|
static struct db_init_query db_upgrade_v8_queries[] =
|
||||||
|
{
|
||||||
|
{ U_V8_GROUPS, "create groups table" },
|
||||||
|
{ U_V8_TRG1, "create trigger update_groups_new_file" },
|
||||||
|
{ U_V8_TRG2, "create trigger update_groups_update_file" },
|
||||||
|
{ U_V8_SCVER, "set schema_version to 8" },
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
db_check_version(void)
|
db_check_version(void)
|
||||||
{
|
{
|
||||||
@ -3604,6 +3637,13 @@ db_check_version(void)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
ret = db_generic_upgrade(db_upgrade_v8_queries, sizeof(db_upgrade_v8_queries) / sizeof(db_upgrade_v8_queries[0]));
|
||||||
|
if (ret < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user