1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Change music folder IDs to int

This commit is contained in:
mvn23 2019-09-14 12:39:05 +02:00
parent d92c5019d9
commit 3e51bf2a6d
5 changed files with 24 additions and 18 deletions

View File

@ -42,7 +42,10 @@ def list_indexes():
if musicFolderId is None: if musicFolderId is None:
folders = Folder.select(lambda f: f.root)[:] folders = Folder.select(lambda f: f.root)[:]
else: else:
mfid = uuid.UUID(musicFolderId) try:
mfid = int(musicFolderId)
except ValueError:
raise ValueError("Invalid folder ID")
folder = Folder[mfid] folder = Folder[mfid]
if not folder.root: if not folder.root:
raise ObjectNotFound(Folder, mfid) raise ObjectNotFound(Folder, mfid)

View File

@ -90,8 +90,13 @@ class IniConfig(DefaultConfig):
lv = value.lower() lv = value.lower()
if lv in ("yes", "true", "on"): if lv in ("yes", "true", "on"):
return True return True
elif lv in ("no", "false", "off"): if lv in ("no", "false", "off"):
return False return False
try:
if isinstance(value, unicode):
return str(value)
except NameError:
pass
return value return value
@classmethod @classmethod

View File

@ -79,7 +79,7 @@ class PathMixin(object):
class Folder(PathMixin, db.Entity): class Folder(PathMixin, db.Entity):
_table_ = "folder" _table_ = "folder"
id = PrimaryKey(UUID, default=uuid4) id = PrimaryKey(int, auto=True)
root = Required(bool, default=False) root = Required(bool, default=False)
name = Required(str, autostrip=False) name = Required(str, autostrip=False)
path = Required(str, 4096, autostrip=False) # unique path = Required(str, 4096, autostrip=False) # unique

View File

@ -21,15 +21,13 @@ from ..py23 import strtype
class FolderManager: class FolderManager:
@staticmethod @staticmethod
def get(uid): def get(id):
if isinstance(uid, strtype): try:
uid = uuid.UUID(uid) id = int(id)
elif isinstance(uid, uuid.UUID): except ValueError:
pass
else:
raise ValueError("Invalid folder id") raise ValueError("Invalid folder id")
return Folder[uid] return Folder[id]
@staticmethod @staticmethod
def add(name, path): def add(name, path):
@ -55,8 +53,8 @@ class FolderManager:
return folder return folder
@staticmethod @staticmethod
def delete(uid): def delete(id):
folder = FolderManager.get(uid) folder = FolderManager.get(id)
if not folder.root: if not folder.root:
raise ObjectNotFound(Folder) raise ObjectNotFound(Folder)

View File

@ -1,5 +1,5 @@
CREATE TABLE IF NOT EXISTS folder ( CREATE TABLE IF NOT EXISTS folder (
id CHAR(36) PRIMARY KEY, id INTEGER NOT NULL PRIMARY KEY,
root BOOLEAN NOT NULL, root BOOLEAN NOT NULL,
name VARCHAR(256) NOT NULL COLLATE NOCASE, name VARCHAR(256) NOT NULL COLLATE NOCASE,
path VARCHAR(4096) NOT NULL, path VARCHAR(4096) NOT NULL,
@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS folder (
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 CHAR(36) REFERENCES folder parent_id INTEGER REFERENCES folder
); );
CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder(parent_id); 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);
@ -42,8 +42,8 @@ CREATE TABLE IF NOT EXISTS track (
last_modification INTEGER NOT NULL, last_modification INTEGER NOT NULL,
play_count INTEGER NOT NULL, play_count INTEGER NOT NULL,
last_play DATETIME, last_play DATETIME,
root_folder_id CHAR(36) NOT NULL REFERENCES folder, root_folder_id INTEGER NOT NULL REFERENCES folder,
folder_id CHAR(36) NOT NULL REFERENCES folder folder_id INTEGER 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_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_artist_id_fk ON track(artist_id);
@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS client_prefs (
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,
starred_id CHAR(36) NOT NULL REFERENCES folder, starred_id INTEGER NOT NULL REFERENCES folder,
date DATETIME NOT NULL, date DATETIME NOT NULL,
PRIMARY KEY (user_id, starred_id) PRIMARY KEY (user_id, starred_id)
); );
@ -111,7 +111,7 @@ CREATE INDEX IF NOT EXISTS index_starred_track_starred_id_fk ON starred_track(st
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,
rated_id CHAR(36) NOT NULL REFERENCES folder, rated_id INTEGER 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)
); );