From 3516afa5ccbc5407fd83d6a121b2b366fa725e63 Mon Sep 17 00:00:00 2001 From: qasimgulzar Date: Mon, 4 Nov 2024 13:24:19 +0500 Subject: [PATCH] fix: migrations to make it postgresql compatible. --- ...nerdatatransmissionaudit_index_together.py | 65 ++++++++++++------- ...nerdatatransmissionaudit_index_together.py | 65 ++++++++++++------- ...nerdatatransmissionaudit_index_together.py | 65 ++++++++++++------- ...nerdatatransmissionaudit_index_together.py | 28 +++++++- ...nerdatatransmissionaudit_index_together.py | 28 +++++++- ...etadataitemtransmission_unique_together.py | 65 ++++++++++++------- ...integratedchannelapirequestlogs_options.py | 6 +- ...nerdatatransmissionaudit_index_together.py | 53 ++++++++++----- ...onaudit_enterprise_course_enrollment_id.py | 3 + ...nerdatatransmissionaudit_index_together.py | 20 ++++-- ...nerdatatransmissionaudit_index_together.py | 21 ++++-- 11 files changed, 298 insertions(+), 121 deletions(-) diff --git a/integrated_channels/blackboard/migrations/0013_alter_blackboardlearnerdatatransmissionaudit_index_together.py b/integrated_channels/blackboard/migrations/0013_alter_blackboardlearnerdatatransmissionaudit_index_together.py index 38d5df14cb..add62a888e 100644 --- a/integrated_channels/blackboard/migrations/0013_alter_blackboardlearnerdatatransmissionaudit_index_together.py +++ b/integrated_channels/blackboard/migrations/0013_alter_blackboardlearnerdatatransmissionaudit_index_together.py @@ -1,8 +1,5 @@ -# Generated by Django 3.2.15 on 2022-12-20 15:05 - from django.db import connection, migrations - class Migration(migrations.Migration): atomic = False @@ -11,6 +8,7 @@ class Migration(migrations.Migration): ] db_engine = connection.settings_dict['ENGINE'] + if 'sqlite3' in db_engine: operations = [ migrations.AlterIndexTogether( @@ -19,23 +17,44 @@ class Migration(migrations.Migration): ), ] else: - operations = [ - migrations.SeparateDatabaseAndState( - state_operations=[ - migrations.AlterIndexTogether( - name='blackboardlearnerdatatransmissionaudit', - index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, - ), - ], - database_operations=[ - migrations.RunSQL(sql=""" - CREATE INDEX blackboard_bldta_85936b55_idx - ON blackboard_blackboardlearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) - ALGORITHM=INPLACE LOCK=NONE - """, reverse_sql=""" - DROP INDEX blackboard_bldta_85936b55_idx - ON blackboard_blackboardlearnerdatatransmissionaudit - """), - ] - ), - ] + if 'postgresql' in db_engine: + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterIndexTogether( + name='blackboardlearnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE INDEX CONCURRENTLY blackboard_bldta_85936b55_idx + ON blackboard_blackboardlearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + """, reverse_sql=""" + DROP INDEX CONCURRENTLY blackboard_bldta_85936b55_idx + """), + ] + ), + ] + else: + # For MySQL or other non-sqlite and non-postgresql backends + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterIndexTogether( + name='blackboardlearnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE INDEX blackboard_bldta_85936b55_idx + ON blackboard_blackboardlearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + ALGORITHM=INPLACE LOCK=NONE + """, reverse_sql=""" + DROP INDEX blackboard_bldta_85936b55_idx + ON blackboard_blackboardlearnerdatatransmissionaudit + """), + ] + ), + ] diff --git a/integrated_channels/canvas/migrations/0028_alter_canvaslearnerdatatransmissionaudit_index_together.py b/integrated_channels/canvas/migrations/0028_alter_canvaslearnerdatatransmissionaudit_index_together.py index a18cd41c0e..b2909abcd2 100644 --- a/integrated_channels/canvas/migrations/0028_alter_canvaslearnerdatatransmissionaudit_index_together.py +++ b/integrated_channels/canvas/migrations/0028_alter_canvaslearnerdatatransmissionaudit_index_together.py @@ -1,8 +1,5 @@ -# Generated by Django 3.2.15 on 2023-01-03 14:33 - from django.db import connection, migrations - class Migration(migrations.Migration): dependencies = [ @@ -10,6 +7,7 @@ class Migration(migrations.Migration): ] db_engine = connection.settings_dict['ENGINE'] + if 'sqlite3' in db_engine: operations = [ migrations.AlterIndexTogether( @@ -18,23 +16,44 @@ class Migration(migrations.Migration): ), ] else: - operations = [ - migrations.SeparateDatabaseAndState( - state_operations=[ - migrations.AlterIndexTogether( - name='canvaslearnerdatatransmissionaudit', - index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, - ), - ], - database_operations=[ - migrations.RunSQL(sql=""" - CREATE INDEX canvas_cldta_85936b55_idx - ON canvas_canvaslearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) - ALGORITHM=INPLACE LOCK=NONE - """, reverse_sql=""" - DROP INDEX canvas_cldta_85936b55_idx - ON canvas_canvaslearnerdatatransmissionaudit - """), - ] - ), - ] + if 'postgresql' in db_engine: + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterIndexTogether( + name='canvaslearnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE INDEX canvas_cldta_85936b55_idx + ON canvas_canvaslearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + """, reverse_sql=""" + DROP INDEX CONCURRENTLY canvas_cldta_85936b55_idx + """), + ] + ), + ] + else: + # For MySQL or other non-sqlite and non-postgresql backends + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterIndexTogether( + name='canvaslearnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE INDEX canvas_cldta_85936b55_idx + ON canvas_canvaslearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + ALGORITHM=INPLACE LOCK=NONE + """, reverse_sql=""" + DROP INDEX canvas_cldta_85936b55_idx + ON canvas_canvaslearnerdatatransmissionaudit + """), + ] + ), + ] diff --git a/integrated_channels/cornerstone/migrations/0025_alter_cornerstonelearnerdatatransmissionaudit_index_together.py b/integrated_channels/cornerstone/migrations/0025_alter_cornerstonelearnerdatatransmissionaudit_index_together.py index 6ff85bb7f0..aeec5584e8 100644 --- a/integrated_channels/cornerstone/migrations/0025_alter_cornerstonelearnerdatatransmissionaudit_index_together.py +++ b/integrated_channels/cornerstone/migrations/0025_alter_cornerstonelearnerdatatransmissionaudit_index_together.py @@ -1,8 +1,5 @@ -# Generated by Django 3.2.15 on 2023-01-03 14:41 - from django.db import connection, migrations - class Migration(migrations.Migration): dependencies = [ @@ -10,6 +7,7 @@ class Migration(migrations.Migration): ] db_engine = connection.settings_dict['ENGINE'] + if 'sqlite3' in db_engine: operations = [ migrations.AlterIndexTogether( @@ -18,23 +16,44 @@ class Migration(migrations.Migration): ), ] else: - operations = [ - migrations.SeparateDatabaseAndState( - state_operations=[ - migrations.AlterIndexTogether( - name='cornerstonelearnerdatatransmissionaudit', - index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, - ), - ], - database_operations=[ - migrations.RunSQL(sql=""" - CREATE INDEX cornerstone_cldta_85936b55_idx - ON cornerstone_cornerstonelearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) - ALGORITHM=INPLACE LOCK=NONE - """, reverse_sql=""" - DROP INDEX cornerstone_cldta_85936b55_idx - ON cornerstone_cornerstonelearnerdatatransmissionaudit - """), - ] - ), - ] + if 'postgresql' in db_engine: + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterIndexTogether( + name='cornerstonelearnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE INDEX cornerstone_cldta_85936b55_idx + ON cornerstone_cornerstonelearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + """, reverse_sql=""" + DROP INDEX cornerstone_cldta_85936b55_idx + """), + ] + ), + ] + else: + # For MySQL or other non-sqlite and non-postgresql backends + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterIndexTogether( + name='cornerstonelearnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE INDEX cornerstone_cldta_85936b55_idx + ON cornerstone_cornerstonelearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + ALGORITHM=INPLACE LOCK=NONE + """, reverse_sql=""" + DROP INDEX cornerstone_cldta_85936b55_idx + ON cornerstone_cornerstonelearnerdatatransmissionaudit + """), + ], + ), + ] diff --git a/integrated_channels/degreed/migrations/0027_alter_degreedlearnerdatatransmissionaudit_index_together.py b/integrated_channels/degreed/migrations/0027_alter_degreedlearnerdatatransmissionaudit_index_together.py index 5d9dfd29c0..a14132a1c5 100644 --- a/integrated_channels/degreed/migrations/0027_alter_degreedlearnerdatatransmissionaudit_index_together.py +++ b/integrated_channels/degreed/migrations/0027_alter_degreedlearnerdatatransmissionaudit_index_together.py @@ -17,7 +17,26 @@ class Migration(migrations.Migration): index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, ), ] - else: + elif 'postgresql' in db_engine: + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterIndexTogether( + name='degreedlearnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE INDEX degreed_dldta_85936b55_idx + ON degreed_degreedlearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + """, reverse_sql=""" + DROP INDEX degreed_dldta_85936b55_idx + """), + ] + ), + ] + elif 'mysql' in db_engine: operations = [ migrations.SeparateDatabaseAndState( state_operations=[ @@ -38,3 +57,10 @@ class Migration(migrations.Migration): ] ), ] + else: + operations = [ + migrations.AlterIndexTogether( + name='degreedlearnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ] diff --git a/integrated_channels/degreed2/migrations/0019_alter_degreed2learnerdatatransmissionaudit_index_together.py b/integrated_channels/degreed2/migrations/0019_alter_degreed2learnerdatatransmissionaudit_index_together.py index c8ace55aaa..3a4fa81ebf 100644 --- a/integrated_channels/degreed2/migrations/0019_alter_degreed2learnerdatatransmissionaudit_index_together.py +++ b/integrated_channels/degreed2/migrations/0019_alter_degreed2learnerdatatransmissionaudit_index_together.py @@ -17,7 +17,26 @@ class Migration(migrations.Migration): index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, ), ] - else: + elif 'postgresql' in db_engine: + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterIndexTogether( + name='degreed2learnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE INDEX degreed2_dldta_85936b55_idx + ON degreed2_degreed2learnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + """, reverse_sql=""" + DROP INDEX degreed2_dldta_85936b55_idx + """), + ] + ), + ] + elif 'mysql' in db_engine: operations = [ migrations.SeparateDatabaseAndState( state_operations=[ @@ -38,3 +57,10 @@ class Migration(migrations.Migration): ] ), ] + else: + operations = [ + migrations.AlterIndexTogether( + name='degreed2learnerdatatransmissionaudit', + index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, + ), + ] diff --git a/integrated_channels/integrated_channel/migrations/0028_alter_contentmetadataitemtransmission_unique_together.py b/integrated_channels/integrated_channel/migrations/0028_alter_contentmetadataitemtransmission_unique_together.py index c2cad1787a..4a146fbfe0 100644 --- a/integrated_channels/integrated_channel/migrations/0028_alter_contentmetadataitemtransmission_unique_together.py +++ b/integrated_channels/integrated_channel/migrations/0028_alter_contentmetadataitemtransmission_unique_together.py @@ -1,14 +1,13 @@ -# Generated by Django 3.2.19 on 2023-06-06 21:40 - from django.db import connection, migrations - class Migration(migrations.Migration): atomic = False dependencies = [ ('integrated_channel', '0027_orphanedcontenttransmissions'), ] + db_engine = connection.settings_dict['ENGINE'] + if 'sqlite3' in db_engine: operations = [ migrations.AlterUniqueTogether( @@ -17,24 +16,44 @@ class Migration(migrations.Migration): ), ] else: - operations = [ - migrations.SeparateDatabaseAndState( - state_operations=[ - migrations.AlterUniqueTogether( - name='contentmetadataitemtransmission', - unique_together={('integrated_channel_code', 'plugin_configuration_id', 'content_id')}, - ), - ], - database_operations=[ - migrations.RunSQL(sql=""" - CREATE UNIQUE INDEX content_transmission_channel_code_plugin_id_content_id_unique - ON integrated_channel_contentmetadataitemtransmission (integrated_channel_code, plugin_configuration_id, content_id) - ALGORITHM=INPLACE LOCK=NONE + if 'postgresql' in db_engine: + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterUniqueTogether( + name='contentmetadataitemtransmission', + unique_together={('integrated_channel_code', 'plugin_configuration_id', 'content_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE UNIQUE INDEX CONCURRENTLY content_transmission_channel_code_plugin_id_content_id_unique + ON integrated_channel_contentmetadataitemtransmission (integrated_channel_code, plugin_configuration_id, content_id) """, reverse_sql=""" - DROP INDEX content_transmission_channel_code_plugin_id_content_id_unique - ON integrated_channel_contentmetadataitemtransmission - """, - ), - ], - ), - ] + DROP INDEX CONCURRENTLY content_transmission_channel_code_plugin_id_content_id_unique + """), + ], + ), + ] + else: + # For MySQL or other non-sqlite and non-postgresql backends + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.AlterUniqueTogether( + name='contentmetadataitemtransmission', + unique_together={('integrated_channel_code', 'plugin_configuration_id', 'content_id')}, + ), + ], + database_operations=[ + migrations.RunSQL(sql=""" + CREATE UNIQUE INDEX content_transmission_channel_code_plugin_id_content_id_unique + ON integrated_channel_contentmetadataitemtransmission (integrated_channel_code, plugin_configuration_id, content_id) + ALGORITHM=INPLACE LOCK=NONE + """, reverse_sql=""" + DROP INDEX content_transmission_channel_code_plugin_id_content_id_unique + ON integrated_channel_contentmetadataitemtransmission + """), + ], + ), + ] diff --git a/integrated_channels/integrated_channel/migrations/0031_alter_integratedchannelapirequestlogs_options.py b/integrated_channels/integrated_channel/migrations/0031_alter_integratedchannelapirequestlogs_options.py index 7f04148866..61946e15fd 100644 --- a/integrated_channels/integrated_channel/migrations/0031_alter_integratedchannelapirequestlogs_options.py +++ b/integrated_channels/integrated_channel/migrations/0031_alter_integratedchannelapirequestlogs_options.py @@ -28,7 +28,11 @@ class Migration(migrations.Migration): name='status_code', field=models.PositiveIntegerField(blank=True, help_text='API call response HTTP status code', null=True), ), - migrations.AlterField( + migrations.RemoveField( + model_name='integratedchannelapirequestlogs', + name='time_taken', + ), + migrations.AddField( model_name='integratedchannelapirequestlogs', name='time_taken', field=models.FloatField(), diff --git a/integrated_channels/moodle/migrations/0023_alter_moodlelearnerdatatransmissionaudit_index_together.py b/integrated_channels/moodle/migrations/0023_alter_moodlelearnerdatatransmissionaudit_index_together.py index 5e709c986f..07d53e50e0 100644 --- a/integrated_channels/moodle/migrations/0023_alter_moodlelearnerdatatransmissionaudit_index_together.py +++ b/integrated_channels/moodle/migrations/0023_alter_moodlelearnerdatatransmissionaudit_index_together.py @@ -3,22 +3,48 @@ from django.db import connection, migrations -class Migration(migrations.Migration): +def generate_index_sql(db_engine): + if 'mysql' in db_engine: + return """ + CREATE INDEX moodle_mldta_85936b55_idx + ON moodle_moodlelearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + ALGORITHM=INPLACE LOCK=NONE + """ + elif 'postgresql' in db_engine: + return """ + CREATE INDEX moodle_mldta_85936b55_idx + ON moodle_moodlelearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + """ + else: + raise ValueError("Unsupported database engine") + + +def drop_index_sql(db_engine): + return """ + DROP INDEX moodle_mldta_85936b55_idx + ON moodle_moodlelearnerdatatransmissionaudit + """ + +class Migration(migrations.Migration): dependencies = [ ('moodle', '0022_auto_20221220_1527'), ] + # Determine the database engine db_engine = connection.settings_dict['ENGINE'] + + operations = [] + if 'sqlite3' in db_engine: - operations = [ + operations.append( migrations.AlterIndexTogether( name='moodlelearnerdatatransmissionaudit', index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, - ), - ] + ) + ) else: - operations = [ + operations.append( migrations.SeparateDatabaseAndState( state_operations=[ migrations.AlterIndexTogether( @@ -27,14 +53,11 @@ class Migration(migrations.Migration): ), ], database_operations=[ - migrations.RunSQL(sql=""" - CREATE INDEX moodle_mldta_85936b55_idx - ON moodle_moodlelearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) - ALGORITHM=INPLACE LOCK=NONE - """, reverse_sql=""" - DROP INDEX moodle_mldta_85936b55_idx - ON moodle_moodlelearnerdatatransmissionaudit - """), + # Adjust SQL for MySQL and PostgreSQL + migrations.RunSQL( + sql=generate_index_sql(db_engine), + reverse_sql=drop_index_sql(db_engine), + ), ] - ), - ] + ) + ) diff --git a/integrated_channels/sap_success_factors/migrations/0001_squashed_0022_auto_20200206_1046_squashed_0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_enterprise_course_enrollment_id.py b/integrated_channels/sap_success_factors/migrations/0001_squashed_0022_auto_20200206_1046_squashed_0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_enterprise_course_enrollment_id.py index 2356272e08..bb6d5472a6 100644 --- a/integrated_channels/sap_success_factors/migrations/0001_squashed_0022_auto_20200206_1046_squashed_0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_enterprise_course_enrollment_id.py +++ b/integrated_channels/sap_success_factors/migrations/0001_squashed_0022_auto_20200206_1046_squashed_0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_enterprise_course_enrollment_id.py @@ -76,5 +76,8 @@ class Migration(migrations.Migration): ('created', models.DateTimeField(auto_now_add=True)), ('credit_hours', models.FloatField(blank=True, null=True)), ], + options={ + 'db_table': 'sap_success_factors_sapsuccessfactorslearnerdatatransmission3ce5', + } ), ] diff --git a/integrated_channels/sap_success_factors/migrations/0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_index_together.py b/integrated_channels/sap_success_factors/migrations/0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_index_together.py index 176186c052..10b9459855 100644 --- a/integrated_channels/sap_success_factors/migrations/0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_index_together.py +++ b/integrated_channels/sap_success_factors/migrations/0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_index_together.py @@ -3,6 +3,20 @@ from django.db import connection, migrations +def generate_index_sql(db_engine): + if 'mysql' in db_engine: + return """ + CREATE INDEX sapsf_sldta_85936b55_idx + ON sap_success_factors_sapsuccessfactorslearnerdatatransmission3ce5 (enterprise_customer_uuid, plugin_configuration_id) + ALGORITHM=INPLACE LOCK=NONE + """ + elif 'postgresql' in db_engine: + return """ + CREATE INDEX sapsf_sldta_85936b55_idx + ON sap_success_factors_sapsuccessfactorslearnerdatatransmission3ce5 (enterprise_customer_uuid, plugin_configuration_id) + """ + + class Migration(migrations.Migration): dependencies = [ @@ -27,11 +41,7 @@ class Migration(migrations.Migration): ), ], database_operations=[ - migrations.RunSQL(sql=""" - CREATE INDEX sapsf_sldta_85936b55_idx - ON sap_success_factors_sapsuccessfactorslearnerdatatransmission3ce5 (enterprise_customer_uuid, plugin_configuration_id) - ALGORITHM=INPLACE LOCK=NONE - """, reverse_sql=""" + migrations.RunSQL(sql=generate_index_sql(db_engine), reverse_sql=""" DROP INDEX sapsf_sldta_85936b55_idx ON sap_success_factors_sapsuccessfactorslearnerdatatransmission3ce5 """), diff --git a/integrated_channels/xapi/migrations/0011_alter_xapilearnerdatatransmissionaudit_index_together.py b/integrated_channels/xapi/migrations/0011_alter_xapilearnerdatatransmissionaudit_index_together.py index 8a509a2b5c..82bc09c500 100644 --- a/integrated_channels/xapi/migrations/0011_alter_xapilearnerdatatransmissionaudit_index_together.py +++ b/integrated_channels/xapi/migrations/0011_alter_xapilearnerdatatransmissionaudit_index_together.py @@ -3,8 +3,21 @@ from django.db import connection, migrations -class Migration(migrations.Migration): +def generate_index_sql(db_engine): + if 'mysql' in db_engine: + return """ + CREATE INDEX xapi_xldta_85936b55_idx + ON xapi_xapilearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + ALGORITHM=INPLACE LOCK=NONE + """ + elif 'postgresql' in db_engine: + return """ + CREATE INDEX xapi_xldta_85936b55_idx + ON xapi_xapilearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) + """ + +class Migration(migrations.Migration): dependencies = [ ('xapi', '0010_auto_20221021_0159'), ] @@ -27,11 +40,7 @@ class Migration(migrations.Migration): ), ], database_operations=[ - migrations.RunSQL(sql=""" - CREATE INDEX xapi_xldta_85936b55_idx - ON xapi_xapilearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) - ALGORITHM=INPLACE LOCK=NONE - """, reverse_sql=""" + migrations.RunSQL(sql=generate_index_sql(db_engine), reverse_sql=""" DROP INDEX xapi_xldta_85936b55_idx ON xapi_xapilearnerdatatransmissionaudit """),