0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

update focal_point_key migrations to delete duplicate renditions

This commit is contained in:
Matt Westcott 2014-10-09 17:04:01 +01:00
parent 1ef27b5b25
commit 44b7fb247d
2 changed files with 14 additions and 0 deletions

View File

@ -4,6 +4,13 @@ from __future__ import unicode_literals
from django.db import models, migrations
def remove_duplicate_renditions(apps, schema_editor):
schema_editor.execute("""
DELETE FROM wagtailimages_rendition WHERE image_id || '-' || filter_id IN (
SELECT image_id || '-' || filter_id FROM wagtailimages_rendition WHERE focal_point_key IS NULL GROUP BY image_id, filter_id HAVING COUNT(*) > 1
) AND focal_point_key IS NULL
""")
class Migration(migrations.Migration):
dependencies = [
@ -11,6 +18,7 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(remove_duplicate_renditions),
migrations.AlterField(
model_name='rendition',
name='focal_point_key',

View File

@ -10,6 +10,12 @@ from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# remove duplicate renditions
db.execute("""
DELETE FROM wagtailimages_rendition WHERE image_id || '-' || filter_id IN (
SELECT image_id || '-' || filter_id FROM wagtailimages_rendition WHERE focal_point_key IS NULL GROUP BY image_id, filter_id HAVING COUNT(*) > 1
) AND focal_point_key IS NULL
""")
# Changing field 'Rendition.focal_point_key'
db.alter_column('wagtailimages_rendition', 'focal_point_key', self.gf('django.db.models.fields.CharField')(max_length=255, default=''))