From 7664ea2073fcaed35f13a7ce6f4234d7b52fef2a Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Tue, 28 Nov 2023 15:26:02 +0000 Subject: [PATCH] fix: only run index queries for Postgres DBs (#3055) --- .../0062_alter_feature_segment_unique_together.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/features/migrations/0062_alter_feature_segment_unique_together.py b/api/features/migrations/0062_alter_feature_segment_unique_together.py index 8ef369b9f585..7671f5077bd2 100644 --- a/api/features/migrations/0062_alter_feature_segment_unique_together.py +++ b/api/features/migrations/0062_alter_feature_segment_unique_together.py @@ -2,13 +2,13 @@ from django.db import migrations +from core.migration_helpers import PostgresOnlyRunSQL current_index_constraint_name = "features_featuresegment_feature_id_environment_i_e5499ca3_uniq" new_index_constraint_name = "features_featuresegment_feature_id_environment_i_f1fde686_uniq" # `atomic = False` only seems to work if each migration.RunSQL argument is a single SQL # statement. As such, we need to split the reverse code into 2 separate RunSQL operations. -# TODO: this will need to be tweaked for Oracle support _drop_constraint_sql = f"ALTER TABLE features_featuresegment DROP CONSTRAINT {current_index_constraint_name};" _drop_constraint_reverse_sql_create_index = f"CREATE UNIQUE INDEX CONCURRENTLY {current_index_constraint_name} ON features_featuresegment USING btree (\"feature_id\", \"environment_id\", \"segment_id\", \"environment_feature_version_id\");" _drop_constraint_reverse_sql_add_constraint = f"ALTER TABLE features_featuresegment ADD CONSTRAINT {current_index_constraint_name} UNIQUE USING INDEX {current_index_constraint_name};" @@ -42,12 +42,12 @@ class Migration(migrations.Migration): ), ], database_operations=[ - migrations.RunSQL(_drop_constraint_sql, reverse_sql=_drop_constraint_reverse_sql_add_constraint), - migrations.RunSQL( + PostgresOnlyRunSQL(_drop_constraint_sql, reverse_sql=_drop_constraint_reverse_sql_add_constraint), + PostgresOnlyRunSQL( migrations.RunSQL.noop, reverse_sql=_drop_constraint_reverse_sql_create_index ), - migrations.RunSQL(_create_index_sql, reverse_sql=_create_index_reverse_sql), - migrations.RunSQL(_add_constraint_sql, reverse_sql=_add_constraint_reverse_sql), + PostgresOnlyRunSQL(_create_index_sql, reverse_sql=_create_index_reverse_sql), + PostgresOnlyRunSQL(_add_constraint_sql, reverse_sql=_add_constraint_reverse_sql), ], ) ]