mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
Automatically create DB tables if needed
This commit is contained in:
parent
9c58b695ff
commit
dbf817ea9e
@ -1,5 +1,6 @@
|
|||||||
include cgi-bin/*
|
include cgi-bin/*
|
||||||
include config.sample
|
include config.sample
|
||||||
include README.md
|
include README.md
|
||||||
|
include supysonic/schema/*
|
||||||
recursive-include supysonic/templates *
|
recursive-include supysonic/templates *
|
||||||
recursive-include supysonic/static *
|
recursive-include supysonic/static *
|
||||||
|
@ -10,13 +10,15 @@
|
|||||||
import time
|
import time
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os.path
|
import os.path
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from pony.orm import Database, Required, Optional, Set, PrimaryKey, LongStr
|
from pony.orm import Database, Required, Optional, Set, PrimaryKey, LongStr
|
||||||
from pony.orm import ObjectNotFound
|
from pony.orm import ObjectNotFound, DatabaseError
|
||||||
from pony.orm import buffer
|
from pony.orm import buffer
|
||||||
from pony.orm import min, max, avg, sum, exists
|
from pony.orm import min, max, avg, sum, exists
|
||||||
|
from pony.orm import db_session
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
from .py23 import dict, strtype
|
from .py23 import dict, strtype
|
||||||
@ -488,7 +490,7 @@ def parse_uri(database_uri):
|
|||||||
elif path[0] == '/':
|
elif path[0] == '/':
|
||||||
path = path[1:]
|
path = path[1:]
|
||||||
|
|
||||||
return dict(provider = 'sqlite', filename = path, **args)
|
return dict(provider = 'sqlite', filename = path, create_db = True, **args)
|
||||||
elif uri.scheme in ('postgres', 'postgresql'):
|
elif uri.scheme in ('postgres', 'postgresql'):
|
||||||
return dict(provider = 'postgres', user = uri.username, password = uri.password, host = uri.hostname, dbname = uri.path[1:], **args)
|
return dict(provider = 'postgres', user = uri.username, password = uri.password, host = uri.hostname, dbname = uri.path[1:], **args)
|
||||||
elif uri.scheme == 'mysql':
|
elif uri.scheme == 'mysql':
|
||||||
@ -496,9 +498,20 @@ def parse_uri(database_uri):
|
|||||||
return dict(provider = 'mysql', user = uri.username, passwd = uri.password, host = uri.hostname, db = uri.path[1:], **args)
|
return dict(provider = 'mysql', user = uri.username, passwd = uri.password, host = uri.hostname, db = uri.path[1:], **args)
|
||||||
return dict()
|
return dict()
|
||||||
|
|
||||||
def init_database(database_uri, create_tables = False):
|
def init_database(database_uri):
|
||||||
db.bind(**parse_uri(database_uri))
|
settings = parse_uri(database_uri)
|
||||||
db.generate_mapping(create_tables = create_tables)
|
db.bind(**settings)
|
||||||
|
db.generate_mapping(check_tables = False)
|
||||||
|
|
||||||
|
try:
|
||||||
|
db.check_tables()
|
||||||
|
except DatabaseError:
|
||||||
|
sql = pkg_resources.resource_string(__package__, 'schema/' + settings['provider'] + '.sql').decode('utf-8')
|
||||||
|
with db_session:
|
||||||
|
for statement in sql.split(';'):
|
||||||
|
statement = statement.strip()
|
||||||
|
if statement:
|
||||||
|
db.execute(statement)
|
||||||
|
|
||||||
def release_database():
|
def release_database():
|
||||||
db.disconnect()
|
db.disconnect()
|
||||||
|
@ -1,29 +1,27 @@
|
|||||||
CREATE TABLE folder (
|
CREATE TABLE IF NOT EXISTS folder (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
root BOOLEAN NOT NULL,
|
root BOOLEAN NOT NULL,
|
||||||
name VARCHAR(256) NOT NULL,
|
name VARCHAR(256) NOT NULL,
|
||||||
path VARCHAR(4096) NOT NULL,
|
path VARCHAR(4096) NOT NULL,
|
||||||
path_hash BINARY(20) NOT NULL,
|
path_hash BINARY(20) UNIQUE NOT NULL,
|
||||||
created DATETIME NOT NULL,
|
created DATETIME NOT NULL,
|
||||||
cover_art VARCHAR(256),
|
cover_art VARCHAR(256),
|
||||||
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 UNIQUE INDEX index_folder_path ON folder(path_hash);
|
CREATE TABLE IF NOT EXISTS artist (
|
||||||
|
|
||||||
CREATE TABLE artist (
|
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
name VARCHAR(256) NOT NULL
|
name VARCHAR(256) NOT NULL
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
CREATE TABLE album (
|
CREATE TABLE IF NOT EXISTS album (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
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 TABLE track (
|
CREATE TABLE IF NOT EXISTS track (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
disc INTEGER NOT NULL,
|
disc INTEGER NOT NULL,
|
||||||
number INTEGER NOT NULL,
|
number INTEGER NOT NULL,
|
||||||
@ -35,7 +33,7 @@ CREATE TABLE track (
|
|||||||
artist_id BINARY(16) NOT NULL REFERENCES artist,
|
artist_id BINARY(16) NOT NULL REFERENCES artist,
|
||||||
bitrate INTEGER NOT NULL,
|
bitrate INTEGER NOT NULL,
|
||||||
path VARCHAR(4096) NOT NULL,
|
path VARCHAR(4096) NOT NULL,
|
||||||
path_hash BINARY(20) NOT NULL,
|
path_hash BINARY(20) UNIQUE NOT NULL,
|
||||||
content_type VARCHAR(32) NOT NULL,
|
content_type VARCHAR(32) NOT NULL,
|
||||||
created DATETIME NOT NULL,
|
created DATETIME NOT NULL,
|
||||||
last_modification INTEGER NOT NULL,
|
last_modification INTEGER NOT NULL,
|
||||||
@ -45,9 +43,7 @@ CREATE TABLE track (
|
|||||||
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 UNIQUE INDEX index_track_path ON track(path_hash);
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
|
|
||||||
CREATE TABLE user (
|
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
name VARCHAR(64) NOT NULL,
|
name VARCHAR(64) NOT NULL,
|
||||||
mail VARCHAR(256),
|
mail VARCHAR(256),
|
||||||
@ -60,7 +56,7 @@ CREATE TABLE user (
|
|||||||
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 TABLE client_prefs (
|
CREATE TABLE IF NOT EXISTS client_prefs (
|
||||||
user_id BINARY(16) NOT NULL,
|
user_id BINARY(16) NOT NULL,
|
||||||
client_name VARCHAR(32) NOT NULL,
|
client_name VARCHAR(32) NOT NULL,
|
||||||
format VARCHAR(8),
|
format VARCHAR(8),
|
||||||
@ -68,56 +64,56 @@ CREATE TABLE client_prefs (
|
|||||||
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 TABLE starred_folder (
|
CREATE TABLE IF NOT EXISTS starred_folder (
|
||||||
user_id BINARY(16) NOT NULL REFERENCES user,
|
user_id BINARY(16) NOT NULL REFERENCES user,
|
||||||
starred_id BINARY(16) NOT NULL REFERENCES folder,
|
starred_id BINARY(16) NOT NULL REFERENCES 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 TABLE 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,
|
||||||
starred_id BINARY(16) NOT NULL REFERENCES artist,
|
starred_id BINARY(16) NOT NULL REFERENCES 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 TABLE 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,
|
||||||
starred_id BINARY(16) NOT NULL REFERENCES album,
|
starred_id BINARY(16) NOT NULL REFERENCES 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 TABLE 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,
|
||||||
starred_id BINARY(16) NOT NULL REFERENCES track,
|
starred_id BINARY(16) NOT NULL REFERENCES 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 TABLE 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,
|
||||||
rated_id BINARY(16) NOT NULL REFERENCES folder,
|
rated_id BINARY(16) NOT NULL REFERENCES 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 TABLE 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,
|
||||||
rated_id BINARY(16) NOT NULL REFERENCES track,
|
rated_id BINARY(16) NOT NULL REFERENCES 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 TABLE chat_message (
|
CREATE TABLE IF NOT EXISTS chat_message (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
user_id BINARY(16) NOT NULL REFERENCES user,
|
user_id BINARY(16) NOT NULL REFERENCES user,
|
||||||
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 TABLE playlist (
|
CREATE TABLE IF NOT EXISTS playlist (
|
||||||
id BINARY(16) PRIMARY KEY,
|
id BINARY(16) PRIMARY KEY,
|
||||||
user_id BINARY(16) NOT NULL REFERENCES user,
|
user_id BINARY(16) NOT NULL REFERENCES user,
|
||||||
name VARCHAR(256) NOT NULL,
|
name VARCHAR(256) NOT NULL,
|
@ -1,29 +1,27 @@
|
|||||||
CREATE TABLE folder (
|
CREATE TABLE IF NOT EXISTS folder (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
root BOOLEAN NOT NULL,
|
root BOOLEAN NOT NULL,
|
||||||
name CITEXT NOT NULL,
|
name CITEXT NOT NULL,
|
||||||
path VARCHAR(4096) NOT NULL,
|
path VARCHAR(4096) NOT NULL,
|
||||||
path_hash BYTEA NOT NULL,
|
path_hash BYTEA UNIQUE NOT NULL,
|
||||||
created TIMESTAMP NOT NULL,
|
created TIMESTAMP NOT NULL,
|
||||||
cover_art VARCHAR(256),
|
cover_art VARCHAR(256),
|
||||||
last_scan INTEGER NOT NULL,
|
last_scan INTEGER NOT NULL,
|
||||||
parent_id UUID REFERENCES folder
|
parent_id UUID REFERENCES folder
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX index_folder_path ON folder(path_hash);
|
CREATE TABLE IF NOT EXISTS artist (
|
||||||
|
|
||||||
CREATE TABLE artist (
|
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
name CITEXT NOT NULL
|
name CITEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE album (
|
CREATE TABLE IF NOT EXISTS album (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
name CITEXT NOT NULL,
|
name CITEXT NOT NULL,
|
||||||
artist_id UUID NOT NULL REFERENCES artist
|
artist_id UUID NOT NULL REFERENCES artist
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE track (
|
CREATE TABLE IF NOT EXISTS track (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
disc INTEGER NOT NULL,
|
disc INTEGER NOT NULL,
|
||||||
number INTEGER NOT NULL,
|
number INTEGER NOT NULL,
|
||||||
@ -35,7 +33,7 @@ CREATE TABLE track (
|
|||||||
artist_id UUID NOT NULL REFERENCES artist,
|
artist_id UUID NOT NULL REFERENCES artist,
|
||||||
bitrate INTEGER NOT NULL,
|
bitrate INTEGER NOT NULL,
|
||||||
path VARCHAR(4096) NOT NULL,
|
path VARCHAR(4096) NOT NULL,
|
||||||
path_hash BYTEA NOT NULL,
|
path_hash BYTEA UNIQUE NOT NULL,
|
||||||
content_type VARCHAR(32) NOT NULL,
|
content_type VARCHAR(32) NOT NULL,
|
||||||
created TIMESTAMP NOT NULL,
|
created TIMESTAMP NOT NULL,
|
||||||
last_modification INTEGER NOT NULL,
|
last_modification INTEGER NOT NULL,
|
||||||
@ -45,9 +43,7 @@ CREATE TABLE track (
|
|||||||
folder_id UUID NOT NULL REFERENCES folder
|
folder_id UUID NOT NULL REFERENCES folder
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX index_track_path ON track(path_hash);
|
CREATE TABLE IF NOT EXISTS "user" (
|
||||||
|
|
||||||
CREATE TABLE "user" (
|
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
name VARCHAR(64) NOT NULL,
|
name VARCHAR(64) NOT NULL,
|
||||||
mail VARCHAR(256),
|
mail VARCHAR(256),
|
||||||
@ -60,7 +56,7 @@ CREATE TABLE "user" (
|
|||||||
last_play_date TIMESTAMP
|
last_play_date TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE client_prefs (
|
CREATE TABLE IF NOT EXISTS client_prefs (
|
||||||
user_id UUID NOT NULL,
|
user_id UUID NOT NULL,
|
||||||
client_name VARCHAR(32) NOT NULL,
|
client_name VARCHAR(32) NOT NULL,
|
||||||
format VARCHAR(8),
|
format VARCHAR(8),
|
||||||
@ -68,56 +64,56 @@ CREATE TABLE client_prefs (
|
|||||||
PRIMARY KEY (user_id, client_name)
|
PRIMARY KEY (user_id, client_name)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE starred_folder (
|
CREATE TABLE IF NOT EXISTS starred_folder (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
starred_id UUID NOT NULL REFERENCES folder,
|
starred_id UUID NOT NULL REFERENCES folder,
|
||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE starred_artist (
|
CREATE TABLE IF NOT EXISTS starred_artist (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
starred_id UUID NOT NULL REFERENCES artist,
|
starred_id UUID NOT NULL REFERENCES artist,
|
||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE starred_album (
|
CREATE TABLE IF NOT EXISTS starred_album (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
starred_id UUID NOT NULL REFERENCES album,
|
starred_id UUID NOT NULL REFERENCES album,
|
||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE starred_track (
|
CREATE TABLE IF NOT EXISTS starred_track (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
starred_id UUID NOT NULL REFERENCES track,
|
starred_id UUID NOT NULL REFERENCES track,
|
||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE rating_folder (
|
CREATE TABLE IF NOT EXISTS rating_folder (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
rated_id UUID NOT NULL REFERENCES folder,
|
rated_id UUID NOT NULL REFERENCES 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 TABLE rating_track (
|
CREATE TABLE IF NOT EXISTS rating_track (
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
rated_id UUID NOT NULL REFERENCES track,
|
rated_id UUID NOT NULL REFERENCES 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 TABLE chat_message (
|
CREATE TABLE IF NOT EXISTS chat_message (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
time INTEGER NOT NULL,
|
time INTEGER NOT NULL,
|
||||||
message VARCHAR(512) NOT NULL
|
message VARCHAR(512) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE playlist (
|
CREATE TABLE IF NOT EXISTS playlist (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
user_id UUID NOT NULL REFERENCES "user",
|
user_id UUID NOT NULL REFERENCES "user",
|
||||||
name VARCHAR(256) NOT NULL,
|
name VARCHAR(256) NOT NULL,
|
@ -1,4 +1,4 @@
|
|||||||
CREATE TABLE folder (
|
CREATE TABLE IF NOT EXISTS folder (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
root BOOLEAN NOT NULL,
|
root BOOLEAN NOT NULL,
|
||||||
name VARCHAR(256) NOT NULL COLLATE NOCASE,
|
name VARCHAR(256) NOT NULL COLLATE NOCASE,
|
||||||
@ -10,20 +10,20 @@ CREATE TABLE folder (
|
|||||||
parent_id CHAR(36) REFERENCES folder
|
parent_id CHAR(36) REFERENCES folder
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX index_folder_path ON folder(path_hash);
|
CREATE UNIQUE INDEX IF NOT EXISTS index_folder_path ON folder(path_hash);
|
||||||
|
|
||||||
CREATE TABLE artist (
|
CREATE TABLE IF NOT EXISTS artist (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
name VARCHAR(256) NOT NULL COLLATE NOCASE
|
name VARCHAR(256) NOT NULL COLLATE NOCASE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE album (
|
CREATE TABLE IF NOT EXISTS album (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
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 TABLE track (
|
CREATE TABLE IF NOT EXISTS track (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
disc INTEGER NOT NULL,
|
disc INTEGER NOT NULL,
|
||||||
number INTEGER NOT NULL,
|
number INTEGER NOT NULL,
|
||||||
@ -45,9 +45,9 @@ CREATE TABLE track (
|
|||||||
folder_id CHAR(36) NOT NULL REFERENCES folder
|
folder_id CHAR(36) NOT NULL REFERENCES folder
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX index_track_path ON track(path_hash);
|
CREATE UNIQUE INDEX IF NOT EXISTS index_track_path ON track(path_hash);
|
||||||
|
|
||||||
CREATE TABLE user (
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
name VARCHAR(64) NOT NULL,
|
name VARCHAR(64) NOT NULL,
|
||||||
mail VARCHAR(256),
|
mail VARCHAR(256),
|
||||||
@ -60,7 +60,7 @@ CREATE TABLE user (
|
|||||||
last_play_date DATETIME
|
last_play_date DATETIME
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE client_prefs (
|
CREATE TABLE IF NOT EXISTS client_prefs (
|
||||||
user_id CHAR(36) NOT NULL,
|
user_id CHAR(36) NOT NULL,
|
||||||
client_name VARCHAR(32) NOT NULL,
|
client_name VARCHAR(32) NOT NULL,
|
||||||
format VARCHAR(8),
|
format VARCHAR(8),
|
||||||
@ -68,56 +68,56 @@ CREATE TABLE client_prefs (
|
|||||||
PRIMARY KEY (user_id, client_name)
|
PRIMARY KEY (user_id, client_name)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE 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,
|
||||||
starred_id CHAR(36) NOT NULL REFERENCES folder,
|
starred_id CHAR(36) NOT NULL REFERENCES folder,
|
||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE 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,
|
||||||
starred_id CHAR(36) NOT NULL REFERENCES artist,
|
starred_id CHAR(36) NOT NULL REFERENCES artist,
|
||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE 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,
|
||||||
starred_id CHAR(36) NOT NULL REFERENCES album,
|
starred_id CHAR(36) NOT NULL REFERENCES album,
|
||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE 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,
|
||||||
starred_id CHAR(36) NOT NULL REFERENCES track,
|
starred_id CHAR(36) NOT NULL REFERENCES track,
|
||||||
date DATETIME NOT NULL,
|
date DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id, starred_id)
|
PRIMARY KEY (user_id, starred_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE 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,
|
||||||
rated_id CHAR(36) NOT NULL REFERENCES folder,
|
rated_id CHAR(36) NOT NULL REFERENCES 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 TABLE 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,
|
||||||
rated_id CHAR(36) NOT NULL REFERENCES track,
|
rated_id CHAR(36) NOT NULL REFERENCES 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 TABLE chat_message (
|
CREATE TABLE IF NOT EXISTS chat_message (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
user_id CHAR(36) NOT NULL REFERENCES user,
|
user_id CHAR(36) NOT NULL REFERENCES user,
|
||||||
time INTEGER NOT NULL,
|
time INTEGER NOT NULL,
|
||||||
message VARCHAR(512) NOT NULL
|
message VARCHAR(512) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE playlist (
|
CREATE TABLE IF NOT EXISTS playlist (
|
||||||
id CHAR(36) PRIMARY KEY,
|
id CHAR(36) PRIMARY KEY,
|
||||||
user_id CHAR(36) NOT NULL REFERENCES user,
|
user_id CHAR(36) NOT NULL REFERENCES user,
|
||||||
name VARCHAR(256) NOT NULL COLLATE NOCASE,
|
name VARCHAR(256) NOT NULL COLLATE NOCASE,
|
@ -34,7 +34,7 @@ class CLITestCase(unittest.TestCase):
|
|||||||
conf = TestConfig(False, False)
|
conf = TestConfig(False, False)
|
||||||
self.__dbfile = tempfile.mkstemp()[1]
|
self.__dbfile = tempfile.mkstemp()[1]
|
||||||
conf.BASE['database_uri'] = 'sqlite:///' + self.__dbfile
|
conf.BASE['database_uri'] = 'sqlite:///' + self.__dbfile
|
||||||
init_database(conf.BASE['database_uri'], True)
|
init_database(conf.BASE['database_uri'])
|
||||||
|
|
||||||
self.__stdout = StringIO()
|
self.__stdout = StringIO()
|
||||||
self.__stderr = StringIO()
|
self.__stderr = StringIO()
|
||||||
|
@ -21,7 +21,7 @@ date_regex = re.compile(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$')
|
|||||||
|
|
||||||
class DbTestCase(unittest.TestCase):
|
class DbTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
db.init_database('sqlite:', True)
|
db.init_database('sqlite:')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.assertRegex
|
self.assertRegex
|
||||||
|
@ -23,7 +23,7 @@ from supysonic.scanner import Scanner
|
|||||||
|
|
||||||
class ScannerTestCase(unittest.TestCase):
|
class ScannerTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
db.init_database('sqlite:', True)
|
db.init_database('sqlite:')
|
||||||
|
|
||||||
with db_session:
|
with db_session:
|
||||||
folder = FolderManager.add('folder', os.path.abspath('tests/assets'))
|
folder = FolderManager.add('folder', os.path.abspath('tests/assets'))
|
||||||
|
@ -42,7 +42,7 @@ class WatcherTestBase(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.__dbfile = tempfile.mkstemp()[1]
|
self.__dbfile = tempfile.mkstemp()[1]
|
||||||
dburi = 'sqlite:///' + self.__dbfile
|
dburi = 'sqlite:///' + self.__dbfile
|
||||||
init_database(dburi, True)
|
init_database(dburi)
|
||||||
release_database()
|
release_database()
|
||||||
|
|
||||||
conf = WatcherTestConfig(dburi)
|
conf = WatcherTestConfig(dburi)
|
||||||
|
@ -22,7 +22,7 @@ from supysonic.scanner import Scanner
|
|||||||
class Issue101TestCase(unittest.TestCase):
|
class Issue101TestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.__dir = tempfile.mkdtemp()
|
self.__dir = tempfile.mkdtemp()
|
||||||
init_database('sqlite:', True)
|
init_database('sqlite:')
|
||||||
with db_session:
|
with db_session:
|
||||||
FolderManager.add('folder', self.__dir)
|
FolderManager.add('folder', self.__dir)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ from pony.orm import db_session, ObjectNotFound
|
|||||||
class FolderManagerTestCase(unittest.TestCase):
|
class FolderManagerTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Create an empty sqlite database in memory
|
# Create an empty sqlite database in memory
|
||||||
db.init_database('sqlite:', True)
|
db.init_database('sqlite:')
|
||||||
|
|
||||||
# Create some temporary directories
|
# Create some temporary directories
|
||||||
self.media_dir = tempfile.mkdtemp()
|
self.media_dir = tempfile.mkdtemp()
|
||||||
|
@ -23,7 +23,7 @@ from pony.orm import ObjectNotFound
|
|||||||
class UserManagerTestCase(unittest.TestCase):
|
class UserManagerTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Create an empty sqlite database in memory
|
# Create an empty sqlite database in memory
|
||||||
db.init_database('sqlite:', True)
|
db.init_database('sqlite:')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
db.release_database()
|
db.release_database()
|
||||||
|
@ -90,7 +90,7 @@ class TestBase(unittest.TestCase):
|
|||||||
config.BASE['database_uri'] = 'sqlite:///' + self.__dbfile
|
config.BASE['database_uri'] = 'sqlite:///' + self.__dbfile
|
||||||
config.WEBAPP['cache_dir'] = self.__dir
|
config.WEBAPP['cache_dir'] = self.__dir
|
||||||
|
|
||||||
init_database(config.BASE['database_uri'], True)
|
init_database(config.BASE['database_uri'])
|
||||||
release_database()
|
release_database()
|
||||||
|
|
||||||
self.__app = create_application(config)
|
self.__app = create_application(config)
|
||||||
|
Loading…
Reference in New Issue
Block a user