From 9112bfa7f2a09bbae798fe23c4308867e2fa9ce1 Mon Sep 17 00:00:00 2001 From: Tobias Macey Date: Mon, 20 Oct 2025 10:44:27 -0400 Subject: [PATCH] fix: Convert UUIDField columns to uuid type for MariaDB Converts UUIDField columns from char(32) to uuid type for MariaDB Django 5 compatibility. See: https://docs.djangoproject.com/en/5.2/releases/5.0/#migrating-uuidfield --- .../0003_mariadb_uuid_conversion.py | 56 +++++++++++++++ .../0044_mariadb_uuid_conversion.py | 66 ++++++++++++++++++ .../0005_mariadb_uuid_conversion.py | 68 +++++++++++++++++++ .../0002_mariadb_uuid_conversion.py | 56 +++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 enterprise_catalog/apps/academy/migrations/0003_mariadb_uuid_conversion.py create mode 100644 enterprise_catalog/apps/catalog/migrations/0044_mariadb_uuid_conversion.py create mode 100644 enterprise_catalog/apps/curation/migrations/0005_mariadb_uuid_conversion.py create mode 100644 enterprise_catalog/apps/jobs/migrations/0002_mariadb_uuid_conversion.py diff --git a/enterprise_catalog/apps/academy/migrations/0003_mariadb_uuid_conversion.py b/enterprise_catalog/apps/academy/migrations/0003_mariadb_uuid_conversion.py new file mode 100644 index 000000000..23ebe4106 --- /dev/null +++ b/enterprise_catalog/apps/academy/migrations/0003_mariadb_uuid_conversion.py @@ -0,0 +1,56 @@ +# Generated migration for MariaDB UUID field conversion (Django 5.2) +""" +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. + +See: https://www.albertyw.com/note/django-5-mariadb-uuidfield +""" + +from django.db import migrations + + +def apply_mariadb_migration(apps, schema_editor): + connection = schema_editor.connection + + if connection.vendor != 'mysql': + return + + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + with connection.cursor() as cursor: + cursor.execute("ALTER TABLE academy_academy MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE academy_historicalacademy MODIFY uuid uuid NOT NULL") + + +def reverse_mariadb_migration(apps, schema_editor): + connection = schema_editor.connection + + if connection.vendor != 'mysql': + return + + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + with connection.cursor() as cursor: + cursor.execute("ALTER TABLE academy_academy MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE academy_historicalacademy MODIFY uuid char(32) NOT NULL") + + +class Migration(migrations.Migration): + + dependencies = [ + ('academy', '0002_tag_content_metadata'), + ] + + operations = [ + migrations.RunPython( + code=apply_mariadb_migration, + reverse_code=reverse_mariadb_migration, + ), + ] diff --git a/enterprise_catalog/apps/catalog/migrations/0044_mariadb_uuid_conversion.py b/enterprise_catalog/apps/catalog/migrations/0044_mariadb_uuid_conversion.py new file mode 100644 index 000000000..d8618b915 --- /dev/null +++ b/enterprise_catalog/apps/catalog/migrations/0044_mariadb_uuid_conversion.py @@ -0,0 +1,66 @@ +# Generated migration for MariaDB UUID field conversion (Django 5.2) +""" +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. + +See: https://www.albertyw.com/note/django-5-mariadb-uuidfield +""" + +from django.db import migrations + + +def apply_mariadb_migration(apps, schema_editor): + connection = schema_editor.connection + + if connection.vendor != 'mysql': + return + + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + with connection.cursor() as cursor: + cursor.execute("ALTER TABLE catalog_catalogquery MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE catalog_enterprisecatalog MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE catalog_enterprisecatalog MODIFY enterprise_uuid uuid NOT NULL") + cursor.execute("ALTER TABLE catalog_historicalenterprisecatalog MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE catalog_historicalenterprisecatalog MODIFY enterprise_uuid uuid NOT NULL") + cursor.execute("ALTER TABLE catalog_contentmetadata MODIFY content_uuid uuid NOT NULL") + cursor.execute("ALTER TABLE catalog_enterprisecatalogroleassignment MODIFY enterprise_id uuid NULL") + + +def reverse_mariadb_migration(apps, schema_editor): + connection = schema_editor.connection + + if connection.vendor != 'mysql': + return + + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + with connection.cursor() as cursor: + cursor.execute("ALTER TABLE catalog_catalogquery MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE catalog_enterprisecatalog MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE catalog_enterprisecatalog MODIFY enterprise_uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE catalog_historicalenterprisecatalog MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE catalog_historicalenterprisecatalog MODIFY enterprise_uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE catalog_contentmetadata MODIFY content_uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE catalog_enterprisecatalogroleassignment MODIFY enterprise_id char(32) NULL") + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalog', '0043_restricted_course_m2m_field'), + ] + + operations = [ + migrations.RunPython( + code=apply_mariadb_migration, + reverse_code=reverse_mariadb_migration, + ), + ] diff --git a/enterprise_catalog/apps/curation/migrations/0005_mariadb_uuid_conversion.py b/enterprise_catalog/apps/curation/migrations/0005_mariadb_uuid_conversion.py new file mode 100644 index 000000000..867619ee3 --- /dev/null +++ b/enterprise_catalog/apps/curation/migrations/0005_mariadb_uuid_conversion.py @@ -0,0 +1,68 @@ +# Generated migration for MariaDB UUID field conversion (Django 5.2) +""" +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. + +See: https://www.albertyw.com/note/django-5-mariadb-uuidfield +""" + +from django.db import migrations + + +def apply_mariadb_migration(apps, schema_editor): + connection = schema_editor.connection + + if connection.vendor != 'mysql': + return + + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + with connection.cursor() as cursor: + cursor.execute("ALTER TABLE curation_enterprisecurationconfig MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE curation_enterprisecurationconfig MODIFY enterprise_uuid uuid NOT NULL") + cursor.execute("ALTER TABLE curation_historicalenterprisecurationconfig MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE curation_historicalenterprisecurationconfig MODIFY enterprise_uuid uuid NOT NULL") + cursor.execute("ALTER TABLE curation_highlightset MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE curation_historicalhighlightset MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE curation_highlightedcontent MODIFY uuid uuid NOT NULL") + cursor.execute("ALTER TABLE curation_historicalhighlightedcontent MODIFY uuid uuid NOT NULL") + + +def reverse_mariadb_migration(apps, schema_editor): + connection = schema_editor.connection + + if connection.vendor != 'mysql': + return + + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + with connection.cursor() as cursor: + cursor.execute("ALTER TABLE curation_enterprisecurationconfig MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE curation_enterprisecurationconfig MODIFY enterprise_uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE curation_historicalenterprisecurationconfig MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE curation_historicalenterprisecurationconfig MODIFY enterprise_uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE curation_highlightset MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE curation_historicalhighlightset MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE curation_highlightedcontent MODIFY uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE curation_historicalhighlightedcontent MODIFY uuid char(32) NOT NULL") + + +class Migration(migrations.Migration): + + dependencies = [ + ('curation', '0004_highlightedcontent_is_favorite_and_more'), + ] + + operations = [ + migrations.RunPython( + code=apply_mariadb_migration, + reverse_code=reverse_mariadb_migration, + ), + ] diff --git a/enterprise_catalog/apps/jobs/migrations/0002_mariadb_uuid_conversion.py b/enterprise_catalog/apps/jobs/migrations/0002_mariadb_uuid_conversion.py new file mode 100644 index 000000000..8a421af22 --- /dev/null +++ b/enterprise_catalog/apps/jobs/migrations/0002_mariadb_uuid_conversion.py @@ -0,0 +1,56 @@ +# Generated migration for MariaDB UUID field conversion (Django 5.2) +""" +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. + +See: https://www.albertyw.com/note/django-5-mariadb-uuidfield +""" + +from django.db import migrations + + +def apply_mariadb_migration(apps, schema_editor): + connection = schema_editor.connection + + if connection.vendor != 'mysql': + return + + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + with connection.cursor() as cursor: + cursor.execute("ALTER TABLE jobs_jobenterprise MODIFY enterprise_uuid uuid NOT NULL") + cursor.execute("ALTER TABLE jobs_historicaljobenterprise MODIFY enterprise_uuid uuid NOT NULL") + + +def reverse_mariadb_migration(apps, schema_editor): + connection = schema_editor.connection + + if connection.vendor != 'mysql': + return + + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + version = cursor.fetchone()[0] + if 'mariadb' not in version.lower(): + return + + with connection.cursor() as cursor: + cursor.execute("ALTER TABLE jobs_jobenterprise MODIFY enterprise_uuid char(32) NOT NULL") + cursor.execute("ALTER TABLE jobs_historicaljobenterprise MODIFY enterprise_uuid char(32) NOT NULL") + + +class Migration(migrations.Migration): + + dependencies = [ + ('jobs', '0001_initial'), + ] + + operations = [ + migrations.RunPython( + code=apply_mariadb_migration, + reverse_code=reverse_mariadb_migration, + ), + ]