mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-10 04:02:17 +00:00
Adding missing foreign key on client_prefs
This commit is contained in:
parent
09a5fb12ed
commit
724f04726e
@ -1,7 +1,7 @@
|
|||||||
# This file is part of Supysonic.
|
# This file is part of Supysonic.
|
||||||
# Supysonic is a Python implementation of the Subsonic server API.
|
# 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.
|
# 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 urllib.parse import urlparse
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
SCHEMA_VERSION = "20230111"
|
SCHEMA_VERSION = "20230115"
|
||||||
|
|
||||||
|
|
||||||
def now():
|
def now():
|
||||||
@ -608,8 +608,9 @@ def init_database(database_uri):
|
|||||||
|
|
||||||
# Check if we should create the tables
|
# Check if we should create the tables
|
||||||
if not db.table_exists("meta"):
|
if not db.table_exists("meta"):
|
||||||
execute_sql_resource_script(f"schema/{provider}.sql")
|
with db.atomic():
|
||||||
Meta.create(key="schema_version", value=SCHEMA_VERSION)
|
execute_sql_resource_script(f"schema/{provider}.sql")
|
||||||
|
Meta.create(key="schema_version", value=SCHEMA_VERSION)
|
||||||
|
|
||||||
# Check for schema changes
|
# Check for schema changes
|
||||||
version = Meta["schema_version"]
|
version = Meta["schema_version"]
|
||||||
@ -618,11 +619,16 @@ def init_database(database_uri):
|
|||||||
pkg_resources.resource_listdir(__package__, f"schema/migration/{provider}")
|
pkg_resources.resource_listdir(__package__, f"schema/migration/{provider}")
|
||||||
)
|
)
|
||||||
for migration in migrations:
|
for migration in migrations:
|
||||||
|
if migration[0] in ("_", "."):
|
||||||
|
continue
|
||||||
|
|
||||||
date, ext = os.path.splitext(migration)
|
date, ext = os.path.splitext(migration)
|
||||||
if date <= version.value:
|
if date <= version.value:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ext == ".sql":
|
if ext == ".sql":
|
||||||
execute_sql_resource_script(f"schema/migration/{provider}/{migration}")
|
with db.atomic():
|
||||||
|
execute_sql_resource_script(f"schema/migration/{provider}/{migration}")
|
||||||
elif ext == ".py":
|
elif ext == ".py":
|
||||||
m = importlib.import_module(
|
m = importlib.import_module(
|
||||||
f".schema.migration.{provider}.{date}", __package__
|
f".schema.migration.{provider}.{date}", __package__
|
||||||
|
2
supysonic/schema/migration/mysql/20230115.sql
Normal file
2
supysonic/schema/migration/mysql/20230115.sql
Normal 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);
|
2
supysonic/schema/migration/postgres/20230115.sql
Normal file
2
supysonic/schema/migration/postgres/20230115.sql
Normal 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);
|
16
supysonic/schema/migration/sqlite/20230115.sql
Normal file
16
supysonic/schema/migration/sqlite/20230115.sql
Normal 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);
|
@ -65,12 +65,13 @@ CREATE TABLE IF NOT EXISTS user (
|
|||||||
CREATE INDEX index_user_last_play_id_fk ON user(last_play_id);
|
CREATE INDEX index_user_last_play_id_fk ON user(last_play_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS client_prefs (
|
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,
|
client_name VARCHAR(32) NOT NULL,
|
||||||
format VARCHAR(8),
|
format VARCHAR(8),
|
||||||
bitrate INTEGER,
|
bitrate INTEGER,
|
||||||
PRIMARY KEY (user_id, client_name)
|
PRIMARY KEY (user_id, client_name)
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) 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 (
|
CREATE TABLE IF NOT EXISTS starred_folder (
|
||||||
user_id CHAR(32) NOT NULL REFERENCES user(id),
|
user_id CHAR(32) NOT NULL REFERENCES user(id),
|
||||||
|
@ -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 INDEX IF NOT EXISTS index_user_last_play_id_fk ON "user"(last_play_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS client_prefs (
|
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,
|
client_name VARCHAR(32) NOT NULL,
|
||||||
format VARCHAR(8),
|
format VARCHAR(8),
|
||||||
bitrate INTEGER,
|
bitrate INTEGER,
|
||||||
PRIMARY KEY (user_id, client_name)
|
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 (
|
CREATE TABLE IF NOT EXISTS starred_folder (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
|
@ -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 INDEX IF NOT EXISTS index_user_last_play_id_fk ON user(last_play_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS client_prefs (
|
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,
|
client_name VARCHAR(32) NOT NULL,
|
||||||
format VARCHAR(8),
|
format VARCHAR(8),
|
||||||
bitrate INTEGER,
|
bitrate INTEGER,
|
||||||
PRIMARY KEY (user_id, client_name)
|
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 (
|
CREATE TABLE IF NOT EXISTS starred_folder (
|
||||||
user_id CHAR(36) NOT NULL REFERENCES user,
|
user_id CHAR(36) NOT NULL REFERENCES user,
|
||||||
|
Loading…
Reference in New Issue
Block a user