Skip to content

Commit

Permalink
Bug 1320136 - Mark redundant RunSQL migration operations as elidable
Browse files Browse the repository at this point in the history
Django's `squashmigrations` command cannot optimise past `RunSQL` or
`RunPython` migration operations, since it cannot guarantee that the
order of migration operations isn't important. However as of Django 1.10
these commands can be marked as `elidable`, if they are not required in
the final migration (eg if they only manipulate legacy data and have
already run in all necessary environments), which solves this problem.
  • Loading branch information
Ed Morley committed Jan 16, 2017
1 parent bd56cca commit 6774130
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions treeherder/model/migrations/0001_initial.py
Expand Up @@ -367,13 +367,19 @@ class Migration(migrations.Migration):
migrations.RunSQL(
sql='CREATE FULLTEXT INDEX `idx_crash_signature` on bugscache (`crash_signature`);',
reverse_sql='ALTER TABLE bugscache DROP INDEX idx_crash_signature',
# Since this cancels out the RunSQL command marked as elidable in 0043_bugscache_cleanup.py.
elidable=True,
),
migrations.RunSQL(
sql='CREATE FULLTEXT INDEX `idx_keywords` on bugscache (`keywords`);',
reverse_sql='ALTER TABLE bugscache DROP INDEX idx_keywords',
# Since this cancels out the RunSQL command marked as elidable in 0043_bugscache_cleanup.py.
elidable=True,
),
migrations.RunSQL(
sql='CREATE FULLTEXT INDEX `idx_all_full_text` on bugscache (`summary`, `crash_signature`, `keywords`);',
reverse_sql='ALTER TABLE bugscache DROP INDEX idx_all_full_text',
# Since this cancels out the RunSQL command marked as elidable in 0043_bugscache_cleanup.py.
elidable=True,
),
]
Expand Up @@ -44,5 +44,8 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(combine_classified_failures, noop)
# Marked as elidable since this migration is only required to fix existing
# bad data (which has already occurred on stage/prod) and so can be omitted
# when this migration is squashed in the future.
migrations.RunPython(combine_classified_failures, noop, elidable=True)
]
Expand Up @@ -15,7 +15,11 @@ class Migration(migrations.Migration):
migrations.RunSQL(
("UPDATE job_detail SET "
" title = SUBSTRING(title, 1, 70), "
" value = SUBSTRING(value, 1, 125)")
" value = SUBSTRING(value, 1, 125)"),
# Marked as elidable since this migration is only required to fix existing
# bad data (which has already occurred on stage/prod) and so can be omitted
# when this migration is squashed in the future.
elidable=True,
),
migrations.AlterField(
model_name='jobdetail',
Expand Down
6 changes: 6 additions & 0 deletions treeherder/model/migrations/0043_bugscache_cleanup.py
Expand Up @@ -31,13 +31,19 @@ class Migration(migrations.Migration):
migrations.RunSQL(
sql='ALTER TABLE bugscache DROP INDEX idx_crash_signature',
reverse_sql='CREATE FULLTEXT INDEX `idx_crash_signature` on bugscache (`crash_signature`);',
# Since this cancels out the RunSQL command marked as elidable in 0001_initial.py.
elidable=True,
),
migrations.RunSQL(
sql='ALTER TABLE bugscache DROP INDEX idx_keywords',
reverse_sql='CREATE FULLTEXT INDEX `idx_keywords` on bugscache (`keywords`);',
# Since this cancels out the RunSQL command marked as elidable in 0001_initial.py.
elidable=True,
),
migrations.RunSQL(
sql='ALTER TABLE bugscache DROP INDEX idx_all_full_text',
reverse_sql='CREATE FULLTEXT INDEX `idx_all_full_text` on bugscache (`summary`, `crash_signature`, `keywords`);',
# Since this cancels out the RunSQL command marked as elidable in 0001_initial.py.
elidable=True,
),
]

0 comments on commit 6774130

Please sign in to comment.