AAP-87829 — Make composite index migration idempotent for upgrade paths (#16585)

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 <noreply@anthropic.com>
This commit is contained in:
Dirk Julich
2026-08-13 13:42:05 -04:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 587b816793
commit d759ff160e
@@ -7,6 +7,14 @@ class Migration(migrations.Migration):
]
operations = [
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(
@@ -14,4 +22,6 @@ class Migration(migrations.Migration):
name='main_jobhostsumm_host_id_desc',
),
),
],
),
]