1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +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:
folders = Folder.select(lambda f: f.root)[:]
else:
mfid = uuid.UUID(musicFolderId)
try:
mfid = int(musicFolderId)
except ValueError:
raise ValueError("Invalid folder ID")
folder = Folder[mfid]
if not folder.root:
raise ObjectNotFound(Folder, mfid)

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
CREATE TABLE IF NOT EXISTS folder (
id CHAR(36) PRIMARY KEY,
id INTEGER NOT NULL PRIMARY KEY,
root BOOLEAN NOT NULL,
name VARCHAR(256) NOT NULL COLLATE NOCASE,
path VARCHAR(4096) NOT NULL,
@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS folder (
created DATETIME NOT NULL,
cover_art VARCHAR(256),
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 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,
play_count INTEGER NOT NULL,
last_play DATETIME,
root_folder_id CHAR(36) NOT NULL REFERENCES folder,
folder_id CHAR(36) NOT NULL REFERENCES folder
root_folder_id INTEGER 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_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 (
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,
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 (
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),
PRIMARY KEY (user_id, rated_id)
);