diff --git a/api/libretime_api/legacy/migrations/0006_2_5_5.py b/api/libretime_api/legacy/migrations/0006_2_5_5.py index 52fe2dd60..5d71f8251 100644 --- a/api/libretime_api/legacy/migrations/0006_2_5_5.py +++ b/api/libretime_api/legacy/migrations/0006_2_5_5.py @@ -8,8 +8,6 @@ UP = """ -- DELETE FROM cc_pref WHERE keystr = 'system_version'; -- INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '2.5.5'); -ALTER TABLE cc_show ADD COLUMN image_path varchar(255) DEFAULT ''; -ALTER TABLE cc_show_instances ADD COLUMN description varchar(255) DEFAULT ''; """ DOWN = None diff --git a/api/libretime_api/legacy/migrations/0015_2_5_17.py b/api/libretime_api/legacy/migrations/0015_2_5_17.py index 0a33a4d1a..110550a2f 100644 --- a/api/libretime_api/legacy/migrations/0015_2_5_17.py +++ b/api/libretime_api/legacy/migrations/0015_2_5_17.py @@ -5,7 +5,7 @@ from django.db import migrations from ._migrations import legacy_migration_factory UP = """ -ALTER TABLE cc_files ADD COLUMN artwork TYPE character varying(255); +ALTER TABLE cc_files ADD COLUMN artwork VARCHAR(255); """ DOWN = None diff --git a/api/libretime_api/legacy/migrations/0023_3_0_0_alpha_9_1.py b/api/libretime_api/legacy/migrations/0023_3_0_0_alpha_9_1.py index bb9911943..bd11e85a9 100644 --- a/api/libretime_api/legacy/migrations/0023_3_0_0_alpha_9_1.py +++ b/api/libretime_api/legacy/migrations/0023_3_0_0_alpha_9_1.py @@ -4,12 +4,18 @@ from django.db import migrations from ._migrations import legacy_migration_factory +# This migration is currently a placeholder for 3.0.0-alpha.9.1. +# Please do not remove it. There are currently no actions, but it +# needs to remain intact so it does not fail when called from the +# migrations script. Any future migrations that may apply to +# 3.0.0-alpha.9.1 will be added to this file. + UP = """ -ALTER TABLE cc_files ADD COLUMN artwork VARCHAR(4096); + """ DOWN = """ -ALTER TABLE cc_files DROP COLUMN IF EXISTS artwork; + """ diff --git a/api/libretime_api/legacy/migrations/_migrations.py b/api/libretime_api/legacy/migrations/_migrations.py index bf0873ef3..cc07d78b1 100644 --- a/api/libretime_api/legacy/migrations/_migrations.py +++ b/api/libretime_api/legacy/migrations/_migrations.py @@ -11,15 +11,28 @@ def get_schema_version(): Don't use django models as they might break in the future. Our concern is to upgrade the legacy database schema to the point where django is in charge of the migrations. + + An airtime 2.5.1 migration will not have schema_version, in that case, we look for + system_version to have a value of 2.5.1 and return that as the schema version value + (really just needs to be anything besides None, so that the next migration doesn't overwrite + the database) """ if "cc_pref" not in connection.introspection.table_names(): return None with connection.cursor() as cursor: - cursor.execute("SELECT valstr FROM cc_pref WHERE keystr = 'schema_version'") + cursor.execute( + """ + SELECT valstr AS version + FROM cc_pref + WHERE (keystr = 'schema_version') OR (keystr = 'system_version' AND valstr = '2.5.1') + """ + ) row = cursor.fetchone() - return row[0] if row else None + if row and row[0]: + return row[0] + return None def set_schema_version(cursor, version: str):