|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# content_assignments - 6 UUIDs |
| 4 | +cat > enterprise_access/apps/content_assignments/migrations/0024_mariadb_uuid_conversion.py << 'EOF' |
| 5 | +# Generated migration for MariaDB UUID field conversion (Django 5.2) |
| 6 | +""" |
| 7 | +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. |
| 8 | +""" |
| 9 | +
|
| 10 | +from django.db import migrations |
| 11 | +
|
| 12 | +
|
| 13 | +def apply_mariadb_migration(apps, schema_editor): |
| 14 | + connection = schema_editor.connection |
| 15 | + if connection.vendor != 'mysql': |
| 16 | + return |
| 17 | + with connection.cursor() as cursor: |
| 18 | + cursor.execute("SELECT VERSION()") |
| 19 | + version = cursor.fetchone()[0] |
| 20 | + if 'mariadb' not in version.lower(): |
| 21 | + return |
| 22 | + with connection.cursor() as cursor: |
| 23 | + cursor.execute("ALTER TABLE content_assignments_assignment MODIFY uuid uuid NOT NULL") |
| 24 | + cursor.execute("ALTER TABLE content_assignments_assignment MODIFY enterprise_customer_uuid uuid NOT NULL") |
| 25 | + cursor.execute("ALTER TABLE content_assignments_learnercontentassignment MODIFY uuid uuid NOT NULL") |
| 26 | + cursor.execute("ALTER TABLE content_assignments_learnercontentassignment MODIFY transaction_uuid uuid NULL") |
| 27 | + cursor.execute("ALTER TABLE content_assignments_learnercontentassignment MODIFY allocation_batch_id uuid NULL") |
| 28 | + cursor.execute("ALTER TABLE content_assignments_assignmentconfiguration MODIFY uuid uuid NOT NULL") |
| 29 | +
|
| 30 | +
|
| 31 | +def reverse_mariadb_migration(apps, schema_editor): |
| 32 | + connection = schema_editor.connection |
| 33 | + if connection.vendor != 'mysql': |
| 34 | + return |
| 35 | + with connection.cursor() as cursor: |
| 36 | + cursor.execute("SELECT VERSION()") |
| 37 | + version = cursor.fetchone()[0] |
| 38 | + if 'mariadb' not in version.lower(): |
| 39 | + return |
| 40 | + with connection.cursor() as cursor: |
| 41 | + cursor.execute("ALTER TABLE content_assignments_assignment MODIFY uuid char(32) NOT NULL") |
| 42 | + cursor.execute("ALTER TABLE content_assignments_assignment MODIFY enterprise_customer_uuid char(32) NOT NULL") |
| 43 | + cursor.execute("ALTER TABLE content_assignments_learnercontentassignment MODIFY uuid char(32) NOT NULL") |
| 44 | + cursor.execute("ALTER TABLE content_assignments_learnercontentassignment MODIFY transaction_uuid char(32) NULL") |
| 45 | + cursor.execute("ALTER TABLE content_assignments_learnercontentassignment MODIFY allocation_batch_id char(32) NULL") |
| 46 | + cursor.execute("ALTER TABLE content_assignments_assignmentconfiguration MODIFY uuid char(32) NOT NULL") |
| 47 | +
|
| 48 | +
|
| 49 | +class Migration(migrations.Migration): |
| 50 | + dependencies = [ |
| 51 | + ('content_assignments', '0023_historicallearnercontentassignment_is_assigned_course_run_and_more'), |
| 52 | + ] |
| 53 | + operations = [ |
| 54 | + migrations.RunPython( |
| 55 | + code=apply_mariadb_migration, |
| 56 | + reverse_code=reverse_mariadb_migration, |
| 57 | + ), |
| 58 | + ] |
| 59 | +EOF |
| 60 | + |
| 61 | +# core - 1 UUID |
| 62 | +cat > enterprise_access/apps/core/migrations/0005_mariadb_uuid_conversion.py << 'EOF' |
| 63 | +# Generated migration for MariaDB UUID field conversion (Django 5.2) |
| 64 | +""" |
| 65 | +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. |
| 66 | +""" |
| 67 | +
|
| 68 | +from django.db import migrations |
| 69 | +
|
| 70 | +
|
| 71 | +def apply_mariadb_migration(apps, schema_editor): |
| 72 | + connection = schema_editor.connection |
| 73 | + if connection.vendor != 'mysql': |
| 74 | + return |
| 75 | + with connection.cursor() as cursor: |
| 76 | + cursor.execute("SELECT VERSION()") |
| 77 | + version = cursor.fetchone()[0] |
| 78 | + if 'mariadb' not in version.lower(): |
| 79 | + return |
| 80 | + with connection.cursor() as cursor: |
| 81 | + cursor.execute("ALTER TABLE core_user MODIFY enterprise_customer_uuid uuid NULL") |
| 82 | +
|
| 83 | +
|
| 84 | +def reverse_mariadb_migration(apps, schema_editor): |
| 85 | + connection = schema_editor.connection |
| 86 | + if connection.vendor != 'mysql': |
| 87 | + return |
| 88 | + with connection.cursor() as cursor: |
| 89 | + cursor.execute("SELECT VERSION()") |
| 90 | + version = cursor.fetchone()[0] |
| 91 | + if 'mariadb' not in version.lower(): |
| 92 | + return |
| 93 | + with connection.cursor() as cursor: |
| 94 | + cursor.execute("ALTER TABLE core_user MODIFY enterprise_customer_uuid char(32) NULL") |
| 95 | +
|
| 96 | +
|
| 97 | +class Migration(migrations.Migration): |
| 98 | + dependencies = [ |
| 99 | + ('core', '0004_auth_user_indexes'), |
| 100 | + ] |
| 101 | + operations = [ |
| 102 | + migrations.RunPython( |
| 103 | + code=apply_mariadb_migration, |
| 104 | + reverse_code=reverse_mariadb_migration, |
| 105 | + ), |
| 106 | + ] |
| 107 | +EOF |
| 108 | + |
| 109 | +# subsidy_access_policy - 7 UUIDs |
| 110 | +cat > enterprise_access/apps/subsidy_access_policy/migrations/0030_mariadb_uuid_conversion.py << 'EOF' |
| 111 | +# Generated migration for MariaDB UUID field conversion (Django 5.2) |
| 112 | +""" |
| 113 | +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. |
| 114 | +""" |
| 115 | +
|
| 116 | +from django.db import migrations |
| 117 | +
|
| 118 | +
|
| 119 | +def apply_mariadb_migration(apps, schema_editor): |
| 120 | + connection = schema_editor.connection |
| 121 | + if connection.vendor != 'mysql': |
| 122 | + return |
| 123 | + with connection.cursor() as cursor: |
| 124 | + cursor.execute("SELECT VERSION()") |
| 125 | + version = cursor.fetchone()[0] |
| 126 | + if 'mariadb' not in version.lower(): |
| 127 | + return |
| 128 | + with connection.cursor() as cursor: |
| 129 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicy MODIFY uuid uuid NOT NULL") |
| 130 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicy MODIFY enterprise_customer_uuid uuid NOT NULL") |
| 131 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicy MODIFY catalog_uuid uuid NOT NULL") |
| 132 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicy MODIFY subsidy_uuid uuid NOT NULL") |
| 133 | + cursor.execute("ALTER TABLE subsidy_access_policy_groupassociation MODIFY enterprise_group_uuid uuid NOT NULL") |
| 134 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicyredemptioncount MODIFY uuid uuid NOT NULL") |
| 135 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicyredemptioncount MODIFY transaction_uuid uuid NOT NULL") |
| 136 | +
|
| 137 | +
|
| 138 | +def reverse_mariadb_migration(apps, schema_editor): |
| 139 | + connection = schema_editor.connection |
| 140 | + if connection.vendor != 'mysql': |
| 141 | + return |
| 142 | + with connection.cursor() as cursor: |
| 143 | + cursor.execute("SELECT VERSION()") |
| 144 | + version = cursor.fetchone()[0] |
| 145 | + if 'mariadb' not in version.lower(): |
| 146 | + return |
| 147 | + with connection.cursor() as cursor: |
| 148 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicy MODIFY uuid char(32) NOT NULL") |
| 149 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicy MODIFY enterprise_customer_uuid char(32) NOT NULL") |
| 150 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicy MODIFY catalog_uuid char(32) NOT NULL") |
| 151 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicy MODIFY subsidy_uuid char(32) NOT NULL") |
| 152 | + cursor.execute("ALTER TABLE subsidy_access_policy_groupassociation MODIFY enterprise_group_uuid char(32) NOT NULL") |
| 153 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicyredemptioncount MODIFY uuid char(32) NOT NULL") |
| 154 | + cursor.execute("ALTER TABLE subsidy_access_policy_subsidyaccesspolicyredemptioncount MODIFY transaction_uuid char(32) NOT NULL") |
| 155 | +
|
| 156 | +
|
| 157 | +class Migration(migrations.Migration): |
| 158 | + dependencies = [ |
| 159 | + ('subsidy_access_policy', '0029_historicalsubsidyaccesspolicy_learner_credit_request_config_and_more'), |
| 160 | + ] |
| 161 | + operations = [ |
| 162 | + migrations.RunPython( |
| 163 | + code=apply_mariadb_migration, |
| 164 | + reverse_code=reverse_mariadb_migration, |
| 165 | + ), |
| 166 | + ] |
| 167 | +EOF |
| 168 | + |
| 169 | +# subsidy_request - 7 UUIDs |
| 170 | +cat > enterprise_access/apps/subsidy_request/migrations/0022_mariadb_uuid_conversion.py << 'EOF' |
| 171 | +# Generated migration for MariaDB UUID field conversion (Django 5.2) |
| 172 | +""" |
| 173 | +Migration to convert UUIDField from char(32) to uuid type for MariaDB compatibility. |
| 174 | +""" |
| 175 | +
|
| 176 | +from django.db import migrations |
| 177 | +
|
| 178 | +
|
| 179 | +def apply_mariadb_migration(apps, schema_editor): |
| 180 | + connection = schema_editor.connection |
| 181 | + if connection.vendor != 'mysql': |
| 182 | + return |
| 183 | + with connection.cursor() as cursor: |
| 184 | + cursor.execute("SELECT VERSION()") |
| 185 | + version = cursor.fetchone()[0] |
| 186 | + if 'mariadb' not in version.lower(): |
| 187 | + return |
| 188 | + with connection.cursor() as cursor: |
| 189 | + cursor.execute("ALTER TABLE subsidy_request_subsidyrequest MODIFY uuid uuid NOT NULL") |
| 190 | + cursor.execute("ALTER TABLE subsidy_request_subsidyrequest MODIFY enterprise_customer_uuid uuid NOT NULL") |
| 191 | + cursor.execute("ALTER TABLE subsidy_request_couponcoderequest MODIFY subscription_plan_uuid uuid NOT NULL") |
| 192 | + cursor.execute("ALTER TABLE subsidy_request_couponcoderequest MODIFY license_uuid uuid NULL") |
| 193 | + cursor.execute("ALTER TABLE subsidy_request_learnercreditrequest MODIFY enterprise_customer_uuid uuid NOT NULL") |
| 194 | + cursor.execute("ALTER TABLE subsidy_request_learnercreditrequest MODIFY uuid uuid NOT NULL") |
| 195 | + cursor.execute("ALTER TABLE subsidy_request_couponcoderequest MODIFY uuid uuid NOT NULL") |
| 196 | +
|
| 197 | +
|
| 198 | +def reverse_mariadb_migration(apps, schema_editor): |
| 199 | + connection = schema_editor.connection |
| 200 | + if connection.vendor != 'mysql': |
| 201 | + return |
| 202 | + with connection.cursor() as cursor: |
| 203 | + cursor.execute("SELECT VERSION()") |
| 204 | + version = cursor.fetchone()[0] |
| 205 | + if 'mariadb' not in version.lower(): |
| 206 | + return |
| 207 | + with connection.cursor() as cursor: |
| 208 | + cursor.execute("ALTER TABLE subsidy_request_subsidyrequest MODIFY uuid char(32) NOT NULL") |
| 209 | + cursor.execute("ALTER TABLE subsidy_request_subsidyrequest MODIFY enterprise_customer_uuid char(32) NOT NULL") |
| 210 | + cursor.execute("ALTER TABLE subsidy_request_couponcoderequest MODIFY subscription_plan_uuid char(32) NOT NULL") |
| 211 | + cursor.execute("ALTER TABLE subsidy_request_couponcoderequest MODIFY license_uuid char(32) NULL") |
| 212 | + cursor.execute("ALTER TABLE subsidy_request_learnercreditrequest MODIFY enterprise_customer_uuid char(32) NOT NULL") |
| 213 | + cursor.execute("ALTER TABLE subsidy_request_learnercreditrequest MODIFY uuid char(32) NOT NULL") |
| 214 | + cursor.execute("ALTER TABLE subsidy_request_couponcoderequest MODIFY uuid char(32) NOT NULL") |
| 215 | +
|
| 216 | +
|
| 217 | +class Migration(migrations.Migration): |
| 218 | + dependencies = [ |
| 219 | + ('subsidy_request', '0021_alter_historicallearnercreditrequestactions_error_reason_and_more'), |
| 220 | + ] |
| 221 | + operations = [ |
| 222 | + migrations.RunPython( |
| 223 | + code=apply_mariadb_migration, |
| 224 | + reverse_code=reverse_mariadb_migration, |
| 225 | + ), |
| 226 | + ] |
| 227 | +EOF |
| 228 | + |
| 229 | +echo "All migration files created successfully!" |
0 commit comments