mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
Add indexes on all foreign keys
Should help with query performance issues such as #140
This commit is contained in:
parent
780c96c404
commit
7ff56bc4ad
@ -31,7 +31,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from urlparse import urlparse, parse_qsl
|
from urlparse import urlparse, parse_qsl
|
||||||
|
|
||||||
SCHEMA_VERSION = '20181010'
|
SCHEMA_VERSION = '20190324'
|
||||||
|
|
||||||
def now():
|
def now():
|
||||||
return datetime.now().replace(microsecond = 0)
|
return datetime.now().replace(microsecond = 0)
|
||||||
|
32
supysonic/schema/migration/mysql/20190324.sql
Normal file
32
supysonic/schema/migration/mysql/20190324.sql
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder(parent_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_album_artist_id_fk ON album(artist_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_album_id_fk ON track(album_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_artist_id_fk ON track(artist_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_folder_id_fk ON track(folder_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_root_folder_id_fk ON track(root_folder_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_user_last_play_id_fk ON user(last_play_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_user_id_fk ON starred_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_starred_id_fk ON starred_folder(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_user_id_fk ON starred_artist(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_starred_id_fk ON starred_artist(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_user_id_fk ON starred_album(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_starred_id_fk ON starred_album(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_user_id_fk ON starred_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_starred_id_fk ON starred_track(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_user_id_fk ON rating_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_rated_id_fk ON rating_folder(rated_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_user_id_fk ON rating_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_rated_id_fk ON rating_track(rated_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_chat_message_user_id_fk ON chat_message(user_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_playlist_user_id_fk ON playlist(user_id);
|
32
supysonic/schema/migration/postgres/20190324.sql
Normal file
32
supysonic/schema/migration/postgres/20190324.sql
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder(parent_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_album_artist_id_fk ON album(artist_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_album_id_fk ON track(album_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_artist_id_fk ON track(artist_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_folder_id_fk ON track(folder_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_root_folder_id_fk ON track(root_folder_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_user_last_play_id_fk ON "user"(last_play_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_user_id_fk ON starred_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_starred_id_fk ON starred_folder(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_user_id_fk ON starred_artist(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_starred_id_fk ON starred_artist(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_user_id_fk ON starred_album(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_starred_id_fk ON starred_album(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_user_id_fk ON starred_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_starred_id_fk ON starred_track(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_user_id_fk ON rating_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_rated_id_fk ON rating_folder(rated_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_user_id_fk ON rating_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_rated_id_fk ON rating_track(rated_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_chat_message_user_id_fk ON chat_message(user_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_playlist_user_id_fk ON playlist(user_id);
|
32
supysonic/schema/migration/sqlite/20190324.sql
Normal file
32
supysonic/schema/migration/sqlite/20190324.sql
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder(parent_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_album_artist_id_fk ON album(artist_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_album_id_fk ON track(album_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_artist_id_fk ON track(artist_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_folder_id_fk ON track(folder_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_root_folder_id_fk ON track(root_folder_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_user_last_play_id_fk ON user(last_play_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_user_id_fk ON starred_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_starred_id_fk ON starred_folder(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_user_id_fk ON starred_artist(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_starred_id_fk ON starred_artist(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_user_id_fk ON starred_album(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_starred_id_fk ON starred_album(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_user_id_fk ON starred_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_starred_id_fk ON starred_track(starred_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_user_id_fk ON rating_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_rated_id_fk ON rating_folder(rated_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_user_id_fk ON rating_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_rated_id_fk ON rating_track(rated_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_chat_message_user_id_fk ON chat_message(user_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS index_playlist_user_id_fk ON playlist(user_id);
|
@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS folder (
|
|||||||
last_scan INTEGER NOT NULL,
|
last_scan INTEGER NOT NULL,
|
||||||
parent_id BINARY(16) REFERENCES folder
|
parent_id BINARY(16) REFERENCES folder
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder(parent_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS artist (
|
CREATE TABLE IF NOT EXISTS artist (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
@ -20,6 +21,7 @@ CREATE TABLE IF NOT EXISTS album (
|
|||||||
name VARCHAR(256) NOT NULL,
|
name VARCHAR(256) NOT NULL,
|
||||||
artist_id BINARY(16) NOT NULL REFERENCES artist
|
artist_id BINARY(16) NOT NULL REFERENCES artist
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_album_artist_id_fk ON album(artist_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS track (
|
CREATE TABLE IF NOT EXISTS track (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
@ -43,6 +45,10 @@ CREATE TABLE IF NOT EXISTS track (
|
|||||||
root_folder_id BINARY(16) NOT NULL REFERENCES folder,
|
root_folder_id BINARY(16) NOT NULL REFERENCES folder,
|
||||||
folder_id BINARY(16) NOT NULL REFERENCES folder
|
folder_id BINARY(16) NOT NULL REFERENCES folder
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_album_id_fk ON track(album_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_artist_id_fk ON track(artist_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_folder_id_fk ON track(folder_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_root_folder_id_fk ON track(root_folder_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS user (
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
@ -56,6 +62,7 @@ CREATE TABLE IF NOT EXISTS user (
|
|||||||
last_play_id BINARY(16) REFERENCES track,
|
last_play_id BINARY(16) REFERENCES track,
|
||||||
last_play_date DATETIME
|
last_play_date DATETIME
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
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 BINARY(16) NOT NULL,
|
user_id BINARY(16) NOT NULL,
|
||||||
@ -71,6 +78,8 @@ CREATE TABLE IF NOT EXISTS starred_folder (
|
|||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_user_id_fk ON starred_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_starred_id_fk ON starred_folder(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_artist (
|
CREATE TABLE IF NOT EXISTS starred_artist (
|
||||||
user_id BINARY(16) NOT NULL REFERENCES user,
|
user_id BINARY(16) NOT NULL REFERENCES user,
|
||||||
@ -78,6 +87,8 @@ CREATE TABLE IF NOT EXISTS starred_artist (
|
|||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_user_id_fk ON starred_artist(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_starred_id_fk ON starred_artist(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_album (
|
CREATE TABLE IF NOT EXISTS starred_album (
|
||||||
user_id BINARY(16) NOT NULL REFERENCES user,
|
user_id BINARY(16) NOT NULL REFERENCES user,
|
||||||
@ -85,6 +96,8 @@ CREATE TABLE IF NOT EXISTS starred_album (
|
|||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_user_id_fk ON starred_album(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_starred_id_fk ON starred_album(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_track (
|
CREATE TABLE IF NOT EXISTS starred_track (
|
||||||
user_id BINARY(16) NOT NULL REFERENCES user,
|
user_id BINARY(16) NOT NULL REFERENCES user,
|
||||||
@ -92,6 +105,8 @@ CREATE TABLE IF NOT EXISTS starred_track (
|
|||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_user_id_fk ON starred_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_starred_id_fk ON starred_track(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS rating_folder (
|
CREATE TABLE IF NOT EXISTS rating_folder (
|
||||||
user_id BINARY(16) NOT NULL REFERENCES user,
|
user_id BINARY(16) NOT NULL REFERENCES user,
|
||||||
@ -99,6 +114,8 @@ CREATE TABLE IF NOT EXISTS rating_folder (
|
|||||||
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
||||||
PRIMARY KEY (user_id, rated_id)
|
PRIMARY KEY (user_id, rated_id)
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_user_id_fk ON rating_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_rated_id_fk ON rating_folder(rated_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS rating_track (
|
CREATE TABLE IF NOT EXISTS rating_track (
|
||||||
user_id BINARY(16) NOT NULL REFERENCES user,
|
user_id BINARY(16) NOT NULL REFERENCES user,
|
||||||
@ -106,6 +123,8 @@ CREATE TABLE IF NOT EXISTS rating_track (
|
|||||||
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
||||||
PRIMARY KEY (user_id, rated_id)
|
PRIMARY KEY (user_id, rated_id)
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_user_id_fk ON rating_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_rated_id_fk ON rating_track(rated_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS chat_message (
|
CREATE TABLE IF NOT EXISTS chat_message (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
@ -113,6 +132,7 @@ CREATE TABLE IF NOT EXISTS chat_message (
|
|||||||
time INTEGER NOT NULL,
|
time INTEGER NOT NULL,
|
||||||
message VARCHAR(512) NOT NULL
|
message VARCHAR(512) NOT NULL
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_chat_message_user_id_fk ON chat_message(user_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS playlist (
|
CREATE TABLE IF NOT EXISTS playlist (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
@ -123,6 +143,7 @@ CREATE TABLE IF NOT EXISTS playlist (
|
|||||||
created DATETIME NOT NULL,
|
created DATETIME NOT NULL,
|
||||||
tracks TEXT
|
tracks TEXT
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
CREATE INDEX IF NOT EXISTS index_playlist_user_id_fk ON playlist(user_id);
|
||||||
|
|
||||||
CREATE TABLE meta (
|
CREATE TABLE meta (
|
||||||
`key` VARCHAR(32) PRIMARY KEY,
|
`key` VARCHAR(32) PRIMARY KEY,
|
||||||
|
@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS folder (
|
|||||||
last_scan INTEGER NOT NULL,
|
last_scan INTEGER NOT NULL,
|
||||||
parent_id UUID REFERENCES folder
|
parent_id UUID REFERENCES folder
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder(parent_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS artist (
|
CREATE TABLE IF NOT EXISTS artist (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
@ -20,6 +21,7 @@ CREATE TABLE IF NOT EXISTS album (
|
|||||||
name CITEXT NOT NULL,
|
name CITEXT NOT NULL,
|
||||||
artist_id UUID NOT NULL REFERENCES artist
|
artist_id UUID NOT NULL REFERENCES artist
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_album_artist_id_fk ON album(artist_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS track (
|
CREATE TABLE IF NOT EXISTS track (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
@ -43,6 +45,10 @@ CREATE TABLE IF NOT EXISTS track (
|
|||||||
root_folder_id UUID NOT NULL REFERENCES folder,
|
root_folder_id UUID NOT NULL REFERENCES folder,
|
||||||
folder_id UUID NOT NULL REFERENCES folder
|
folder_id UUID NOT NULL REFERENCES folder
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_album_id_fk ON track(album_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_artist_id_fk ON track(artist_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_folder_id_fk ON track(folder_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_root_folder_id_fk ON track(root_folder_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS "user" (
|
CREATE TABLE IF NOT EXISTS "user" (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
@ -56,6 +62,7 @@ CREATE TABLE IF NOT EXISTS "user" (
|
|||||||
last_play_id UUID REFERENCES track,
|
last_play_id UUID REFERENCES track,
|
||||||
last_play_date TIMESTAMP
|
last_play_date TIMESTAMP
|
||||||
);
|
);
|
||||||
|
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,
|
||||||
@ -71,6 +78,8 @@ CREATE TABLE IF NOT EXISTS starred_folder (
|
|||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_user_id_fk ON starred_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_starred_id_fk ON starred_folder(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_artist (
|
CREATE TABLE IF NOT EXISTS starred_artist (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
@ -78,6 +87,8 @@ CREATE TABLE IF NOT EXISTS starred_artist (
|
|||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_user_id_fk ON starred_artist(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_starred_id_fk ON starred_artist(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_album (
|
CREATE TABLE IF NOT EXISTS starred_album (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
@ -85,6 +96,8 @@ CREATE TABLE IF NOT EXISTS starred_album (
|
|||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_user_id_fk ON starred_album(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_starred_id_fk ON starred_album(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_track (
|
CREATE TABLE IF NOT EXISTS starred_track (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
@ -92,6 +105,8 @@ CREATE TABLE IF NOT EXISTS starred_track (
|
|||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_user_id_fk ON starred_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_starred_id_fk ON starred_track(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS rating_folder (
|
CREATE TABLE IF NOT EXISTS rating_folder (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
@ -99,6 +114,8 @@ CREATE TABLE IF NOT EXISTS rating_folder (
|
|||||||
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
||||||
PRIMARY KEY (user_id, rated_id)
|
PRIMARY KEY (user_id, rated_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_user_id_fk ON rating_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_rated_id_fk ON rating_folder(rated_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS rating_track (
|
CREATE TABLE IF NOT EXISTS rating_track (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
@ -106,6 +123,8 @@ CREATE TABLE IF NOT EXISTS rating_track (
|
|||||||
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
||||||
PRIMARY KEY (user_id, rated_id)
|
PRIMARY KEY (user_id, rated_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_user_id_fk ON rating_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_rated_id_fk ON rating_track(rated_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS chat_message (
|
CREATE TABLE IF NOT EXISTS chat_message (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
@ -113,6 +132,7 @@ CREATE TABLE IF NOT EXISTS chat_message (
|
|||||||
time INTEGER NOT NULL,
|
time INTEGER NOT NULL,
|
||||||
message VARCHAR(512) NOT NULL
|
message VARCHAR(512) NOT NULL
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_chat_message_user_id_fk ON chat_message(user_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS playlist (
|
CREATE TABLE IF NOT EXISTS playlist (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
@ -123,6 +143,7 @@ CREATE TABLE IF NOT EXISTS playlist (
|
|||||||
created TIMESTAMP NOT NULL,
|
created TIMESTAMP NOT NULL,
|
||||||
tracks TEXT
|
tracks TEXT
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_playlist_user_id_fk ON playlist(user_id);
|
||||||
|
|
||||||
CREATE TABLE meta (
|
CREATE TABLE meta (
|
||||||
key VARCHAR(32) PRIMARY KEY,
|
key VARCHAR(32) PRIMARY KEY,
|
||||||
|
@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS folder (
|
|||||||
last_scan INTEGER NOT NULL,
|
last_scan INTEGER NOT NULL,
|
||||||
parent_id CHAR(36) REFERENCES folder
|
parent_id CHAR(36) REFERENCES folder
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder(parent_id);
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS index_folder_path ON folder(path_hash);
|
CREATE UNIQUE INDEX IF NOT EXISTS index_folder_path ON folder(path_hash);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS artist (
|
CREATE TABLE IF NOT EXISTS artist (
|
||||||
@ -22,6 +22,7 @@ CREATE TABLE IF NOT EXISTS album (
|
|||||||
name VARCHAR(256) NOT NULL COLLATE NOCASE,
|
name VARCHAR(256) NOT NULL COLLATE NOCASE,
|
||||||
artist_id CHAR(36) NOT NULL REFERENCES artist
|
artist_id CHAR(36) NOT NULL REFERENCES artist
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_album_artist_id_fk ON album(artist_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS track (
|
CREATE TABLE IF NOT EXISTS track (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
@ -45,7 +46,10 @@ CREATE TABLE IF NOT EXISTS track (
|
|||||||
root_folder_id CHAR(36) NOT NULL REFERENCES folder,
|
root_folder_id CHAR(36) NOT NULL REFERENCES folder,
|
||||||
folder_id CHAR(36) NOT NULL REFERENCES folder
|
folder_id CHAR(36) NOT NULL REFERENCES folder
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_album_id_fk ON track(album_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_artist_id_fk ON track(artist_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_folder_id_fk ON track(folder_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_track_root_folder_id_fk ON track(root_folder_id);
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS index_track_path ON track(path_hash);
|
CREATE UNIQUE INDEX IF NOT EXISTS index_track_path ON track(path_hash);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS user (
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
@ -60,6 +64,7 @@ CREATE TABLE IF NOT EXISTS user (
|
|||||||
last_play_id CHAR(36) REFERENCES track,
|
last_play_id CHAR(36) REFERENCES track,
|
||||||
last_play_date DATETIME
|
last_play_date DATETIME
|
||||||
);
|
);
|
||||||
|
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,
|
||||||
@ -75,6 +80,8 @@ CREATE TABLE IF NOT EXISTS starred_folder (
|
|||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_user_id_fk ON starred_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_folder_starred_id_fk ON starred_folder(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_artist (
|
CREATE TABLE IF NOT EXISTS starred_artist (
|
||||||
user_id CHAR(36) NOT NULL REFERENCES user,
|
user_id CHAR(36) NOT NULL REFERENCES user,
|
||||||
@ -82,6 +89,8 @@ CREATE TABLE IF NOT EXISTS starred_artist (
|
|||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_user_id_fk ON starred_artist(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_artist_starred_id_fk ON starred_artist(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_album (
|
CREATE TABLE IF NOT EXISTS starred_album (
|
||||||
user_id CHAR(36) NOT NULL REFERENCES user,
|
user_id CHAR(36) NOT NULL REFERENCES user,
|
||||||
@ -89,6 +98,8 @@ CREATE TABLE IF NOT EXISTS starred_album (
|
|||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_user_id_fk ON starred_album(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_album_starred_id_fk ON starred_album(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS starred_track (
|
CREATE TABLE IF NOT EXISTS starred_track (
|
||||||
user_id CHAR(36) NOT NULL REFERENCES user,
|
user_id CHAR(36) NOT NULL REFERENCES user,
|
||||||
@ -96,6 +107,8 @@ CREATE TABLE IF NOT EXISTS starred_track (
|
|||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_user_id_fk ON starred_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_starred_track_starred_id_fk ON starred_track(starred_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS rating_folder (
|
CREATE TABLE IF NOT EXISTS rating_folder (
|
||||||
user_id CHAR(36) NOT NULL REFERENCES user,
|
user_id CHAR(36) NOT NULL REFERENCES user,
|
||||||
@ -103,6 +116,8 @@ CREATE TABLE IF NOT EXISTS rating_folder (
|
|||||||
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
||||||
PRIMARY KEY (user_id, rated_id)
|
PRIMARY KEY (user_id, rated_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_user_id_fk ON rating_folder(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_folder_rated_id_fk ON rating_folder(rated_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS rating_track (
|
CREATE TABLE IF NOT EXISTS rating_track (
|
||||||
user_id CHAR(36) NOT NULL REFERENCES user,
|
user_id CHAR(36) NOT NULL REFERENCES user,
|
||||||
@ -110,6 +125,8 @@ CREATE TABLE IF NOT EXISTS rating_track (
|
|||||||
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5),
|
||||||
PRIMARY KEY (user_id, rated_id)
|
PRIMARY KEY (user_id, rated_id)
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_user_id_fk ON rating_track(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_rating_track_rated_id_fk ON rating_track(rated_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS chat_message (
|
CREATE TABLE IF NOT EXISTS chat_message (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
@ -117,6 +134,7 @@ CREATE TABLE IF NOT EXISTS chat_message (
|
|||||||
time INTEGER NOT NULL,
|
time INTEGER NOT NULL,
|
||||||
message VARCHAR(512) NOT NULL
|
message VARCHAR(512) NOT NULL
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_chat_message_user_id_fk ON chat_message(user_id);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS playlist (
|
CREATE TABLE IF NOT EXISTS playlist (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
@ -127,6 +145,7 @@ CREATE TABLE IF NOT EXISTS playlist (
|
|||||||
created DATETIME NOT NULL,
|
created DATETIME NOT NULL,
|
||||||
tracks TEXT
|
tracks TEXT
|
||||||
);
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS index_playlist_user_id_fk ON playlist(user_id);
|
||||||
|
|
||||||
CREATE TABLE meta (
|
CREATE TABLE meta (
|
||||||
key CHAR(32) PRIMARY KEY,
|
key CHAR(32) PRIMARY KEY,
|
||||||
|
Loading…
Reference in New Issue
Block a user