mirror of
https://github.com/ansible/awx.git
synced 2026-10-29 22:03:20 -02:30
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:
co-authored by
Claude Opus 4.6
parent
587b816793
commit
d759ff160e
@@ -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',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user