From d759ff160e1269b5e2679cf3c8aeabfad3475575 Mon Sep 17 00:00:00 2001 From: Dirk Julich Date: Thu, 13 Aug 2026 19:42:05 +0200 Subject: [PATCH] =?UTF-8?q?AAP-87829=20=E2=80=94=20Make=20composite=20inde?= =?UTF-8?q?x=20migration=20idempotent=20for=20upgrade=20paths=20(#16585)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use SeparateDatabaseAndState with CREATE INDEX IF NOT EXISTS so the migration succeeds when the index was already created manually (via awx-manage create_host_summary_index or raw SQL workaround). Forward-port of tower#7895 (stable-2.7). Co-authored-by: Claude Opus 4.6 --- .../0206_jobhostsummary_host_id_idx.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/awx/main/migrations/0206_jobhostsummary_host_id_idx.py b/awx/main/migrations/0206_jobhostsummary_host_id_idx.py index 13617aaefc..8607bc92f6 100644 --- a/awx/main/migrations/0206_jobhostsummary_host_id_idx.py +++ b/awx/main/migrations/0206_jobhostsummary_host_id_idx.py @@ -7,11 +7,21 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AddIndex( - model_name='jobhostsummary', - index=models.Index( - fields=['host', '-id'], - name='main_jobhostsumm_host_id_desc', - ), + migrations.SeparateDatabaseAndState( + database_operations=[ + migrations.RunSQL( + sql="CREATE INDEX IF NOT EXISTS main_jobhostsumm_host_id_desc ON main_jobhostsummary (host_id, id DESC)", + reverse_sql="DROP INDEX IF EXISTS main_jobhostsumm_host_id_desc", + ), + ], + state_operations=[ + migrations.AddIndex( + model_name='jobhostsummary', + index=models.Index( + fields=['host', '-id'], + name='main_jobhostsumm_host_id_desc', + ), + ), + ], ), ]