From 639c68291a7a719dc54cafbfc118bf497ce6c5e6 Mon Sep 17 00:00:00 2001 From: Carey Metcalfe Date: Fri, 31 Mar 2023 20:40:28 -0400 Subject: [PATCH] Add database migrations to fix up the bitrate units The migration assumes that no audio files will be <16kbps and only wav files will be more than 16,000kbps. --- supysonic/db.py | 2 +- supysonic/schema/migration/mysql/20230331.sql | 5 +++++ supysonic/schema/migration/postgres/20230331.sql | 5 +++++ supysonic/schema/migration/sqlite/20230331.sql | 8 ++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 supysonic/schema/migration/mysql/20230331.sql create mode 100644 supysonic/schema/migration/postgres/20230331.sql create mode 100644 supysonic/schema/migration/sqlite/20230331.sql diff --git a/supysonic/db.py b/supysonic/db.py index 0c745cd..4ab3a45 100644 --- a/supysonic/db.py +++ b/supysonic/db.py @@ -31,7 +31,7 @@ from playhouse.db_url import parseresult_to_dict, schemes from urllib.parse import urlparse from uuid import UUID, uuid4 -SCHEMA_VERSION = "20230115" +SCHEMA_VERSION = "20230331" def now(): diff --git a/supysonic/schema/migration/mysql/20230331.sql b/supysonic/schema/migration/mysql/20230331.sql new file mode 100644 index 0000000..030a7bf --- /dev/null +++ b/supysonic/schema/migration/mysql/20230331.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +UPDATE track SET bitrate=bitrate/1000 WHERE bitrate > 16000 AND path NOT LIKE '%.wav'; + +COMMIT; diff --git a/supysonic/schema/migration/postgres/20230331.sql b/supysonic/schema/migration/postgres/20230331.sql new file mode 100644 index 0000000..030a7bf --- /dev/null +++ b/supysonic/schema/migration/postgres/20230331.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +UPDATE track SET bitrate=bitrate/1000 WHERE bitrate > 16000 AND path NOT LIKE '%.wav'; + +COMMIT; diff --git a/supysonic/schema/migration/sqlite/20230331.sql b/supysonic/schema/migration/sqlite/20230331.sql new file mode 100644 index 0000000..45e7b22 --- /dev/null +++ b/supysonic/schema/migration/sqlite/20230331.sql @@ -0,0 +1,8 @@ +COMMIT; +PRAGMA foreign_keys = OFF; +BEGIN TRANSACTION; + +UPDATE track SET bitrate=bitrate/1000 WHERE bitrate > 16000 AND path NOT LIKE '%.wav'; + +COMMIT; +BEGIN TRANSACTION;