From 0d79f9efb31f993148e1433291ae4a90f0b860a1 Mon Sep 17 00:00:00 2001 From: Jesper Hodge Date: Fri, 21 Feb 2025 11:32:53 -0500 Subject: [PATCH] fix: make migration work for sqlite for testing --- ...enterprisecustomeruser_user_fk_and_more.py | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/enterprise/migrations/0230_alter_enterprisecustomeruser_user_fk_and_more.py b/enterprise/migrations/0230_alter_enterprisecustomeruser_user_fk_and_more.py index c7c32a25d..1deaad3c3 100644 --- a/enterprise/migrations/0230_alter_enterprisecustomeruser_user_fk_and_more.py +++ b/enterprise/migrations/0230_alter_enterprisecustomeruser_user_fk_and_more.py @@ -1,31 +1,34 @@ # Generated by Django 4.2.16 on 2025-02-19 20:20 -from django.db import migrations, models +from django.db import migrations, connection class Migration(migrations.Migration): - dependencies = [ ('enterprise', '0229_enterprisecustomeruser_user_fk_and_more'), ] - operations = [ - # Custom SQL to add indexes with zero-downtime options - migrations.RunSQL( - sql=""" - ALTER TABLE enterprise_enterprisecustomeruser - ADD INDEX idx_enterprise_user_fk (user_fk), - ALGORITHM=INPLACE, - LOCK=NONE; + db_engine = connection.settings_dict['ENGINE'] + if 'sqlite3' in db_engine: + operations = [] + else: + operations = [ + # Custom SQL to add indexes with zero-downtime options + migrations.RunSQL( + sql=""" + ALTER TABLE enterprise_enterprisecustomeruser + ADD INDEX idx_enterprise_user_fk (user_fk), + ALGORITHM=INPLACE, + LOCK=NONE; - ALTER TABLE enterprise_historicalenterprisecustomeruser - ADD INDEX idx_historical_enterprise_user_fk (user_fk), - ALGORITHM=INPLACE, - LOCK=NONE; - """, - reverse_sql=""" - ALTER TABLE enterprise_enterprisecustomeruser DROP INDEX idx_enterprise_user_fk; - ALTER TABLE enterprise_historicalenterprisecustomeruser DROP INDEX idx_historical_enterprise_user_fk; - """ - ), - ] \ No newline at end of file + ALTER TABLE enterprise_historicalenterprisecustomeruser + ADD INDEX idx_historical_enterprise_user_fk (user_fk), + ALGORITHM=INPLACE, + LOCK=NONE; + """, + reverse_sql=""" + ALTER TABLE enterprise_enterprisecustomeruser DROP INDEX idx_enterprise_user_fk; + ALTER TABLE enterprise_historicalenterprisecustomeruser DROP INDEX idx_historical_enterprise_user_fk; + """ + ), + ]