mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-26 09:34:50 +00:00
update focal_point_key migrations to delete duplicate renditions
This commit is contained in:
parent
1ef27b5b25
commit
44b7fb247d
2 changed files with 14 additions and 0 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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=''))
|
||||
|
|
|
|||
Loading…
Reference in a new issue