From 3f433cb221b35cd1d98d9abc8c19b0a8b68cf6d6 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Wed, 25 Jan 2017 12:53:42 +0000 Subject: [PATCH] Fiddle max_length in focal_point_key migrations to make them superficially different This prevents the migration engine from optimising them away - see https://github.com/wagtail/wagtail/pull/3293#issuecomment-274828807 --- wagtail/wagtailimages/migrations/0001_initial.py | 2 +- .../migrations/0004_make_focal_point_key_not_nullable.py | 2 +- .../0016_deprecate_rendition_filter_relation.py | 8 +++++++- .../migrations/0017_reduce_focal_point_key_max_length.py | 6 +++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/wagtail/wagtailimages/migrations/0001_initial.py b/wagtail/wagtailimages/migrations/0001_initial.py index e8c29d7a66..4040bd7db9 100644 --- a/wagtail/wagtailimages/migrations/0001_initial.py +++ b/wagtail/wagtailimages/migrations/0001_initial.py @@ -63,7 +63,7 @@ class Migration(migrations.Migration): ('file', models.ImageField(width_field='width', upload_to='images', height_field='height')), ('width', models.IntegerField(editable=False)), ('height', models.IntegerField(editable=False)), - ('focal_point_key', models.CharField(editable=False, max_length=16, null=True)), + ('focal_point_key', models.CharField(editable=False, max_length=18, null=True)), ('filter', models.ForeignKey(on_delete=models.CASCADE, related_name='+', to='wagtailimages.Filter')), ('image', models.ForeignKey(on_delete=models.CASCADE, related_name='renditions', to='wagtailimages.Image')), ], diff --git a/wagtail/wagtailimages/migrations/0004_make_focal_point_key_not_nullable.py b/wagtail/wagtailimages/migrations/0004_make_focal_point_key_not_nullable.py index a6c8601842..8ee4c67f93 100644 --- a/wagtail/wagtailimages/migrations/0004_make_focal_point_key_not_nullable.py +++ b/wagtail/wagtailimages/migrations/0004_make_focal_point_key_not_nullable.py @@ -44,6 +44,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='rendition', name='focal_point_key', - field=models.CharField(blank=True, default='', max_length=16, editable=False), + field=models.CharField(blank=True, default='', max_length=18, editable=False), ), ] diff --git a/wagtail/wagtailimages/migrations/0016_deprecate_rendition_filter_relation.py b/wagtail/wagtailimages/migrations/0016_deprecate_rendition_filter_relation.py index 44d51fb39e..2ff40f39f4 100644 --- a/wagtail/wagtailimages/migrations/0016_deprecate_rendition_filter_relation.py +++ b/wagtail/wagtailimages/migrations/0016_deprecate_rendition_filter_relation.py @@ -35,6 +35,12 @@ class Migration(migrations.Migration): # that successfully applied the old 1.8 version of this migration are consistent with # other setups. # + # Since Django will optimise away any AlterField operations that appear to match + # the current state (according to earlier migrations) - which would cause them to be + # skipped on installations that ran the earlier (max_length=255) versions of the + # migrations - we need to make them superficially different; we do this by stepping + # max_length down from 18 to 17 then 16. + # # Projects with a custom image model don't have to worry about this - they'll have an existing # migration with the max_length=255, and will get a new migration reducing it to max_length=16 # the next time they run makemigrations. @@ -42,7 +48,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='rendition', name='focal_point_key', - field=models.CharField(blank=True, default='', max_length=16, editable=False), + field=models.CharField(blank=True, default='', max_length=17, editable=False), ), migrations.AlterUniqueTogether( diff --git a/wagtail/wagtailimages/migrations/0017_reduce_focal_point_key_max_length.py b/wagtail/wagtailimages/migrations/0017_reduce_focal_point_key_max_length.py index b8350d1e89..b31d4c4bc9 100644 --- a/wagtail/wagtailimages/migrations/0017_reduce_focal_point_key_max_length.py +++ b/wagtail/wagtailimages/migrations/0017_reduce_focal_point_key_max_length.py @@ -13,9 +13,9 @@ class Migration(migrations.Migration): operations = [ # The Wagtail 1.8 version of migration wagtailimages/0016 did not include the # step to reduce focal_point_key's max_length to 16, necessary to make it work - # on some MySQL configurations. This migration serves only to ensure that - # installations upgrading from 1.8 to >=1.8.1 have this change applied; on other - # setups (where the current 0016 and 0017 are applied together), this is a no-op. + # on some MySQL configurations. This migration (added in 1.8.1) ensures that + # installations that were already successfully running 1.8 receive this change + # on upgrading to 1.8.1 or later. migrations.AlterField( model_name='rendition', name='focal_point_key',