mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Merge pull request #1692 from FlipperPA/master
Create custom SQL for SQL Server. Yes, it had to be that ugly, but it…
This commit is contained in:
commit
6ffa06624f
@ -11,6 +11,19 @@ def remove_duplicate_renditions(apps, schema_editor):
|
|||||||
SELECT CONCAT(image_id, '-', filter_id) FROM (SELECT * FROM `wagtailimages_rendition`) as x WHERE `focal_point_key` IS NULL GROUP BY image_id, filter_id HAVING COUNT(*) > 1
|
SELECT CONCAT(image_id, '-', filter_id) FROM (SELECT * FROM `wagtailimages_rendition`) as x WHERE `focal_point_key` IS NULL GROUP BY image_id, filter_id HAVING COUNT(*) > 1
|
||||||
) AND `focal_point_key` IS NULL
|
) AND `focal_point_key` IS NULL
|
||||||
""")
|
""")
|
||||||
|
elif schema_editor.connection.vendor == 'microsoft':
|
||||||
|
schema_editor.execute("""
|
||||||
|
DELETE FROM [wagtailimages_rendition] WHERE CAST(image_id AS VARCHAR(MAX)) + '-' + CAST(filter_id AS VARCHAR(MAX)) IN (
|
||||||
|
SELECT CAST(image_id AS VARCHAR(MAX)) + '-' + CAST(filter_id AS VARCHAR(MAX)) FROM [wagtailimages_rendition] WHERE focal_point_key IS NULL GROUP BY image_id, filter_id HAVING COUNT(*) > 1
|
||||||
|
) AND focal_point_key IS NULL
|
||||||
|
""")
|
||||||
|
schema_editor.execute("""
|
||||||
|
DECLARE @constraint_name VARCHAR(MAX)
|
||||||
|
SELECT @constraint_name = CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME='wagtailimages_rendition' AND CONSTRAINT_TYPE='UNIQUE'
|
||||||
|
EXEC('ALTER TABLE [wagtailimages_rendition] DROP CONSTRAINT ' + @constraint_name)
|
||||||
|
ALTER TABLE [wagtailimages_rendition] ALTER COLUMN [focal_point_key] NVARCHAR(255) NOT NULL
|
||||||
|
EXEC('ALTER TABLE [wagtailimages_rendition] ADD CONSTRAINT ' + @constraint_name + ' UNIQUE NONCLUSTERED (image_id, filter_id, focal_point_key)')
|
||||||
|
""")
|
||||||
else:
|
else:
|
||||||
schema_editor.execute("""
|
schema_editor.execute("""
|
||||||
DELETE FROM wagtailimages_rendition WHERE image_id || '-' || filter_id IN (
|
DELETE FROM wagtailimages_rendition WHERE image_id || '-' || filter_id IN (
|
||||||
@ -26,6 +39,7 @@ class Migration(migrations.Migration):
|
|||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RunPython(remove_duplicate_renditions),
|
migrations.RunPython(remove_duplicate_renditions),
|
||||||
|
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='rendition',
|
model_name='rendition',
|
||||||
name='focal_point_key',
|
name='focal_point_key',
|
||||||
|
Loading…
Reference in New Issue
Block a user