Skip to content

Commit 801fbd1

Browse files
blarghmateyormsbee
authored andcommitted
fix: Convert UUIDField columns to uuid type for MariaDB
Converts UUIDField columns from char(32) to uuid type for MariaDB Django 5 compatibility. This migration converts the following column: - workflow_assessmentworkflow.uuid See: https://docs.djangoproject.com/en/5.2/releases/5.0/#migrating-uuidfield
1 parent 430b908 commit 801fbd1

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

openassessment/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Initialization Information for Open Assessment Module
33
"""
44

5-
__version__ = '6.17.0'
5+
__version__ = '6.17.1'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Generated migration for MariaDB UUID field conversion (Django 5.2)
2+
"""
3+
Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility.
4+
5+
This migration is necessary because Django 5 changed the behavior of UUIDField for MariaDB
6+
databases from using CharField(32) to using a proper UUID type. This change isn't managed
7+
automatically, so we need to generate migrations to safely convert the columns.
8+
9+
This migration only executes for MariaDB databases and is a no-op for other backends.
10+
11+
See: https://www.albertyw.com/note/django-5-mariadb-uuidfield
12+
"""
13+
14+
from django.db import migrations
15+
16+
17+
def apply_mariadb_migration(apps, schema_editor):
18+
"""Apply the migration only for MariaDB databases."""
19+
connection = schema_editor.connection
20+
21+
# Check if this is a MariaDB database
22+
if connection.vendor != 'mysql':
23+
return
24+
25+
# Additional check for MariaDB specifically (vs MySQL)
26+
with connection.cursor() as cursor:
27+
cursor.execute("SELECT VERSION()")
28+
version = cursor.fetchone()[0]
29+
if 'mariadb' not in version.lower():
30+
return
31+
32+
# Apply the field changes for MariaDB
33+
with connection.cursor() as cursor:
34+
cursor.execute(
35+
"ALTER TABLE workflow_assessmentworkflow "
36+
"MODIFY uuid uuid NOT NULL"
37+
)
38+
39+
40+
def reverse_mariadb_migration(apps, schema_editor):
41+
"""Reverse the migration only for MariaDB databases."""
42+
connection = schema_editor.connection
43+
44+
# Check if this is a MariaDB database
45+
if connection.vendor != 'mysql':
46+
return
47+
48+
# Additional check for MariaDB specifically (vs MySQL)
49+
with connection.cursor() as cursor:
50+
cursor.execute("SELECT VERSION()")
51+
version = cursor.fetchone()[0]
52+
if 'mariadb' not in version.lower():
53+
return
54+
55+
# Reverse the field changes for MariaDB
56+
with connection.cursor() as cursor:
57+
cursor.execute(
58+
"ALTER TABLE workflow_assessmentworkflow "
59+
"MODIFY uuid char(32) NOT NULL"
60+
)
61+
62+
63+
class Migration(migrations.Migration):
64+
65+
dependencies = [
66+
('workflow', '0005_alter_assessmentworkflow_status'),
67+
]
68+
69+
operations = [
70+
migrations.RunPython(
71+
code=apply_mariadb_migration,
72+
reverse_code=reverse_mariadb_migration,
73+
),
74+
]

0 commit comments

Comments
 (0)