1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-09-19 19:01:03 +00:00

Adding missing foreign key on client_prefs

This commit is contained in:
Alban Féron 2023-01-15 15:51:27 +01:00
parent 09a5fb12ed
commit 724f04726e
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
7 changed files with 37 additions and 8 deletions

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2013-2022 Alban 'spl0k' Féron
# Copyright (C) 2013-2023 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
@ -31,7 +31,7 @@ from playhouse.db_url import parseresult_to_dict, schemes
from urllib.parse import urlparse
from uuid import UUID, uuid4
SCHEMA_VERSION = "20230111"
SCHEMA_VERSION = "20230115"
def now():
@ -608,6 +608,7 @@ def init_database(database_uri):
# Check if we should create the tables
if not db.table_exists("meta"):
with db.atomic():
execute_sql_resource_script(f"schema/{provider}.sql")
Meta.create(key="schema_version", value=SCHEMA_VERSION)
@ -618,10 +619,15 @@ def init_database(database_uri):
pkg_resources.resource_listdir(__package__, f"schema/migration/{provider}")
)
for migration in migrations:
if migration[0] in ("_", "."):
continue
date, ext = os.path.splitext(migration)
if date <= version.value:
continue
if ext == ".sql":
with db.atomic():
execute_sql_resource_script(f"schema/migration/{provider}/{migration}")
elif ext == ".py":
m = importlib.import_module(

View File

@ -0,0 +1,2 @@
ALTER TABLE client_prefs ADD FOREIGN KEY (user_id) REFERENCES user(id);
CREATE INDEX IF NOT EXISTS index_client_prefs_user_id_fk ON client_prefs(user_id);

View File

@ -0,0 +1,2 @@
ALTER TABLE client_prefs ADD FOREIGN KEY (user_id) REFERENCES "user";
CREATE INDEX IF NOT EXISTS index_client_prefs_user_id_fk ON client_prefs(user_id);

View File

@ -0,0 +1,16 @@
CREATE TABLE client_prefs_new (
user_id CHAR(36) NOT NULL REFERENCES user,
client_name VARCHAR(32) NOT NULL,
format VARCHAR(8),
bitrate INTEGER,
PRIMARY KEY (user_id, client_name)
);
INSERT INTO client_prefs_new(user_id, client_name, format, bitrate)
SELECT user_id, client_name, format, bitrate
FROM client_prefs;
DROP TABLE client_prefs;
ALTER TABLE client_prefs_new RENAME TO client_prefs;
CREATE INDEX IF NOT EXISTS index_client_prefs_user_id_fk ON client_prefs(user_id);

View File

@ -65,12 +65,13 @@ CREATE TABLE IF NOT EXISTS user (
CREATE INDEX index_user_last_play_id_fk ON user(last_play_id);
CREATE TABLE IF NOT EXISTS client_prefs (
user_id CHAR(32) NOT NULL,
user_id CHAR(32) NOT NULL REFERENCES user(id),
client_name VARCHAR(32) NOT NULL,
format VARCHAR(8),
bitrate INTEGER,
PRIMARY KEY (user_id, client_name)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE INDEX index_client_prefs_user_id_fk ON client_prefs(user_id);
CREATE TABLE IF NOT EXISTS starred_folder (
user_id CHAR(32) NOT NULL REFERENCES user(id),

View File

@ -65,12 +65,13 @@ CREATE TABLE IF NOT EXISTS "user" (
CREATE INDEX IF NOT EXISTS index_user_last_play_id_fk ON "user"(last_play_id);
CREATE TABLE IF NOT EXISTS client_prefs (
user_id UUID NOT NULL,
user_id UUID NOT NULL REFERENCES "user",
client_name VARCHAR(32) NOT NULL,
format VARCHAR(8),
bitrate INTEGER,
PRIMARY KEY (user_id, client_name)
);
CREATE INDEX IF NOT EXISTS index_client_prefs_user_id_fk ON client_prefs(user_id);
CREATE TABLE IF NOT EXISTS starred_folder (
user_id UUID NOT NULL REFERENCES "user",

View File

@ -67,12 +67,13 @@ CREATE TABLE IF NOT EXISTS user (
CREATE INDEX IF NOT EXISTS index_user_last_play_id_fk ON user(last_play_id);
CREATE TABLE IF NOT EXISTS client_prefs (
user_id CHAR(36) NOT NULL,
user_id CHAR(36) NOT NULL REFERENCES user,
client_name VARCHAR(32) NOT NULL,
format VARCHAR(8),
bitrate INTEGER,
PRIMARY KEY (user_id, client_name)
);
CREATE INDEX IF NOT EXISTS index_client_prefs_user_id_fk ON client_prefs(user_id);
CREATE TABLE IF NOT EXISTS starred_folder (
user_id CHAR(36) NOT NULL REFERENCES user,