Skip to content

Commit bcec184

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: - openedx_ledger_transaction.idempotency_key See: https://docs.djangoproject.com/en/5.2/releases/5.0/#migrating-uuidfield
1 parent 291a0fa commit bcec184

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

openedx_ledger/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""
22
A library that records transactions against a ledger, denominated in units of value.
33
"""
4-
__version__ = "1.6.12"
4+
__version__ = "1.6.13"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
6+
from django.db import migrations
7+
8+
9+
def apply_mariadb_migration(apps, schema_editor):
10+
connection = schema_editor.connection
11+
if connection.vendor != 'mysql':
12+
return
13+
with connection.cursor() as cursor:
14+
cursor.execute("SELECT VERSION()")
15+
version = cursor.fetchone()[0]
16+
if 'mariadb' not in version.lower():
17+
return
18+
with connection.cursor() as cursor:
19+
cursor.execute("ALTER TABLE openedx_ledger_transaction MODIFY idempotency_key uuid NULL")
20+
21+
22+
def reverse_mariadb_migration(apps, schema_editor):
23+
connection = schema_editor.connection
24+
if connection.vendor != 'mysql':
25+
return
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+
with connection.cursor() as cursor:
32+
cursor.execute("ALTER TABLE openedx_ledger_transaction MODIFY idempotency_key char(32) NULL")
33+
34+
35+
class Migration(migrations.Migration):
36+
dependencies = [
37+
('openedx_ledger', '0015_add_course_run_start_date_to_transaction'),
38+
]
39+
operations = [
40+
migrations.RunPython(
41+
code=apply_mariadb_migration,
42+
reverse_code=reverse_mariadb_migration,
43+
),
44+
]

0 commit comments

Comments
 (0)