mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-04 10:26:02 -05:00
[db] Minor version upgrade: new column "path" in directories table
This commit is contained in:
parent
60220a8133
commit
42cbd721fd
11
src/db.c
11
src/db.c
@ -3944,6 +3944,7 @@ db_directory_enum_fetch(struct directory_enum *de, struct directory_info *di)
|
||||
disabled = sqlite3_column_int64(de->stmt, 3);
|
||||
di->disabled = (disabled != 0);
|
||||
di->parent_id = sqlite3_column_int(de->stmt, 4);
|
||||
di->path = (char *)sqlite3_column_text(de->stmt, 5);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -3961,8 +3962,8 @@ db_directory_enum_end(struct directory_enum *de)
|
||||
static int
|
||||
db_directory_add(struct directory_info *di, int *id)
|
||||
{
|
||||
#define QADD_TMPL "INSERT INTO directories (virtual_path, db_timestamp, disabled, parent_id)" \
|
||||
" VALUES (TRIM(%Q), %d, %d, %d);"
|
||||
#define QADD_TMPL "INSERT INTO directories (virtual_path, db_timestamp, disabled, parent_id, path)" \
|
||||
" VALUES (TRIM(%Q), %d, %d, %d, TRIM(%Q));"
|
||||
|
||||
char *query;
|
||||
char *errmsg;
|
||||
@ -3977,7 +3978,7 @@ db_directory_add(struct directory_info *di, int *id)
|
||||
DPRINTF(E_LOG, L_DB, "Directory name ends with space: '%s'\n", di->virtual_path);
|
||||
}
|
||||
|
||||
query = sqlite3_mprintf(QADD_TMPL, di->virtual_path, di->db_timestamp, di->disabled, di->parent_id);
|
||||
query = sqlite3_mprintf(QADD_TMPL, di->virtual_path, di->db_timestamp, di->disabled, di->parent_id, di->path);
|
||||
|
||||
if (!query)
|
||||
{
|
||||
@ -4016,14 +4017,14 @@ db_directory_add(struct directory_info *di, int *id)
|
||||
static int
|
||||
db_directory_update(struct directory_info *di)
|
||||
{
|
||||
#define QADD_TMPL "UPDATE directories SET virtual_path = TRIM(%Q), db_timestamp = %d, disabled = %d, parent_id = %d" \
|
||||
#define QADD_TMPL "UPDATE directories SET virtual_path = TRIM(%Q), db_timestamp = %d, disabled = %d, parent_id = %d, path = TRIM(%Q)" \
|
||||
" WHERE id = %d;"
|
||||
char *query;
|
||||
char *errmsg;
|
||||
int ret;
|
||||
|
||||
/* Add */
|
||||
query = sqlite3_mprintf(QADD_TMPL, di->virtual_path, di->db_timestamp, di->disabled, di->parent_id, di->id);
|
||||
query = sqlite3_mprintf(QADD_TMPL, di->virtual_path, di->db_timestamp, di->disabled, di->parent_id, di->path, di->id);
|
||||
|
||||
if (!query)
|
||||
{
|
||||
|
1
src/db.h
1
src/db.h
@ -412,6 +412,7 @@ enum directory_ids {
|
||||
struct directory_info {
|
||||
uint32_t id;
|
||||
char *virtual_path;
|
||||
char *path;
|
||||
uint32_t db_timestamp;
|
||||
uint32_t disabled;
|
||||
uint32_t parent_id;
|
||||
|
@ -161,7 +161,8 @@
|
||||
" virtual_path VARCHAR(4096) NOT NULL," \
|
||||
" db_timestamp INTEGER DEFAULT 0," \
|
||||
" disabled INTEGER DEFAULT 0," \
|
||||
" parent_id INTEGER DEFAULT 0" \
|
||||
" parent_id INTEGER DEFAULT 0," \
|
||||
" path VARCHAR(4096) DEFAULT NULL" \
|
||||
");"
|
||||
|
||||
#define T_QUEUE \
|
||||
@ -239,17 +240,17 @@
|
||||
|
||||
|
||||
#define Q_DIR1 \
|
||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||
" VALUES (1, '/', 0, 0, 0);"
|
||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id, path)" \
|
||||
" VALUES (1, '/', 0, 0, 0, NULL);"
|
||||
#define Q_DIR2 \
|
||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||
" VALUES (2, '/file:', 0, 0, 1);"
|
||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id, path)" \
|
||||
" VALUES (2, '/file:', 0, 0, 1, '/');"
|
||||
#define Q_DIR3 \
|
||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||
" VALUES (3, '/http:', 0, 0, 1);"
|
||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id, path)" \
|
||||
" VALUES (3, '/http:', 0, 0, 1, NULL);"
|
||||
#define Q_DIR4 \
|
||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||
" VALUES (4, '/spotify:', 0, 4294967296, 1);"
|
||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id, path)" \
|
||||
" VALUES (4, '/spotify:', 0, 4294967296, 1, NULL);"
|
||||
|
||||
#define Q_QUEUE_VERSION \
|
||||
"INSERT INTO admin (key, value) VALUES ('queue_version', '0');"
|
||||
|
@ -26,7 +26,7 @@
|
||||
* is a major upgrade. In other words minor version upgrades permit downgrading
|
||||
* forked-daapd after the database was upgraded. */
|
||||
#define SCHEMA_VERSION_MAJOR 19
|
||||
#define SCHEMA_VERSION_MINOR 11
|
||||
#define SCHEMA_VERSION_MINOR 12
|
||||
|
||||
int
|
||||
db_init_indices(sqlite3 *hdl);
|
||||
|
@ -1698,6 +1698,27 @@ static const struct db_upgrade_query db_upgrade_v1911_queries[] =
|
||||
};
|
||||
|
||||
|
||||
#define U_V1912_ALTER_DIRECTORIES_ADD_PATH \
|
||||
"ALTER TABLE directories ADD COLUMN path VARCHAR(4096) DEFAULT NULL;"
|
||||
|
||||
#define U_V1912_UPDATE_FILE_DIRECTORIES_PATH \
|
||||
"UPDATE directories SET path = SUBSTR(path, 7) WHERE virtual_path like '/file:/%';"
|
||||
#define U_V1912_UPDATE_FILE_ROOT_PATH \
|
||||
"UPDATE directories SET path = '/' WHERE virtual_path = '/file:';"
|
||||
|
||||
#define U_V1912_SCVER_MINOR \
|
||||
"UPDATE admin SET value = '12' WHERE key = 'schema_version_minor';"
|
||||
|
||||
static const struct db_upgrade_query db_upgrade_v1912_queries[] =
|
||||
{
|
||||
{ U_V1912_ALTER_DIRECTORIES_ADD_PATH, "alter table directories add column path" },
|
||||
{ U_V1912_UPDATE_FILE_DIRECTORIES_PATH, "set paths for '/file:' directories" },
|
||||
{ U_V1912_UPDATE_FILE_ROOT_PATH, "set path for '/file:' directory" },
|
||||
|
||||
{ U_V1912_SCVER_MINOR, "set schema_version_minor to 12" },
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
db_upgrade(sqlite3 *hdl, int db_ver)
|
||||
{
|
||||
@ -1884,6 +1905,14 @@ db_upgrade(sqlite3 *hdl, int db_ver)
|
||||
ret = db_generic_upgrade(hdl, db_upgrade_v1911_queries, ARRAY_SIZE(db_upgrade_v1911_queries));
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case 1911:
|
||||
ret = db_generic_upgrade(hdl, db_upgrade_v1912_queries, ARRAY_SIZE(db_upgrade_v1912_queries));
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user