mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-15 08:45:02 -05:00
Simplify DB init routine
This commit is contained in:
parent
944bf3f132
commit
fefdb23409
43
src/db.c
43
src/db.c
@ -2890,10 +2890,6 @@ db_perthread_deinit(void)
|
||||
" libidx INTEGER NOT NULL" \
|
||||
");"
|
||||
|
||||
#define Q_PL1 \
|
||||
"INSERT INTO playlists (id, title, type, query, db_timestamp, path, idx)" \
|
||||
" VALUES(1, 'Library', 1, '1', 0, '', 0);"
|
||||
|
||||
#define I_PATH \
|
||||
"CREATE INDEX IF NOT EXISTS idx_path ON files(path, idx);"
|
||||
|
||||
@ -2904,6 +2900,11 @@ db_perthread_deinit(void)
|
||||
"CREATE INDEX IF NOT EXISTS idx_playlistid ON playlistitems(playlistid, filepath);"
|
||||
|
||||
|
||||
#define Q_PL1 \
|
||||
"INSERT INTO playlists (id, title, type, query, db_timestamp, path, idx)" \
|
||||
" VALUES(1, 'Library', 1, '1', 0, '', 0);"
|
||||
|
||||
|
||||
#define SCHEMA_VERSION 3
|
||||
#define Q_SCVER \
|
||||
"INSERT INTO admin (key, value) VALUES ('schema_version', '3');"
|
||||
@ -2924,6 +2925,10 @@ static struct db_init_query db_init_queries[] =
|
||||
{ I_PATH, "create file path index" },
|
||||
{ I_FILEPATH, "create file path index" },
|
||||
{ I_PLITEMID, "create playlist id index" },
|
||||
|
||||
{ Q_PL1, "create default playlist" },
|
||||
|
||||
{ Q_SCVER, "set schema version" },
|
||||
};
|
||||
|
||||
static int
|
||||
@ -2947,36 +2952,6 @@ db_create_tables(void)
|
||||
}
|
||||
}
|
||||
|
||||
ret = db_get_count("SELECT COUNT(*) FROM playlists WHERE id = 1;");
|
||||
if (ret != 1)
|
||||
{
|
||||
DPRINTF(E_DBG, L_DB, "Creating default playlist\n");
|
||||
|
||||
ret = sqlite3_exec(hdl, Q_PL1, NULL, NULL, &errmsg);
|
||||
if (ret != SQLITE_OK)
|
||||
{
|
||||
DPRINTF(E_FATAL, L_DB, "Could not add default playlist: %s\n", errmsg);
|
||||
|
||||
sqlite3_free(errmsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = db_get_count("SELECT COUNT(*) FROM admin WHERE key = 'schema_version';");
|
||||
if (ret != 1)
|
||||
{
|
||||
DPRINTF(E_DBG, L_DB, "Setting schema version\n");
|
||||
|
||||
ret = sqlite3_exec(hdl, Q_SCVER, NULL, NULL, &errmsg);
|
||||
if (ret != SQLITE_OK)
|
||||
{
|
||||
DPRINTF(E_FATAL, L_DB, "Could not set schema version: %s\n", errmsg);
|
||||
|
||||
sqlite3_free(errmsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user