Apply some fixes over epic custom attributes
parent
e2f6245fbb
commit
15aa7da858
|
@ -15,50 +15,50 @@ class Migration(migrations.Migration):
|
||||||
# Function: Remove a key in a json field
|
# Function: Remove a key in a json field
|
||||||
migrations.RunSQL(
|
migrations.RunSQL(
|
||||||
"""
|
"""
|
||||||
CREATE OR REPLACE FUNCTION "json_object_delete_keys"("json" json, VARIADIC "keys_to_delete" text[])
|
CREATE OR REPLACE FUNCTION "json_object_delete_keys"("json" json, VARIADIC "keys_to_delete" text[])
|
||||||
RETURNS json
|
RETURNS json
|
||||||
LANGUAGE sql
|
LANGUAGE sql
|
||||||
IMMUTABLE
|
IMMUTABLE
|
||||||
STRICT
|
STRICT
|
||||||
AS $function$
|
AS $function$
|
||||||
SELECT COALESCE ((SELECT ('{' || string_agg(to_json("key") || ':' || "value", ',') || '}')
|
SELECT COALESCE ((SELECT ('{' || string_agg(to_json("key") || ':' || "value", ',') || '}')
|
||||||
FROM json_each("json")
|
FROM json_each("json")
|
||||||
WHERE "key" <> ALL ("keys_to_delete")),
|
WHERE "key" <> ALL ("keys_to_delete")),
|
||||||
'{}')::json $function$;
|
'{}')::json $function$;
|
||||||
""",
|
""",
|
||||||
reverse_sql="""DROP FUNCTION IF EXISTS "json_object_delete_keys"("json" json, VARIADIC "keys_to_delete" text[])
|
reverse_sql="""
|
||||||
CASCADE;"""
|
DROP FUNCTION IF EXISTS "json_object_delete_keys"("json" json, VARIADIC "keys_to_delete" text[])
|
||||||
|
CASCADE;"""
|
||||||
),
|
),
|
||||||
|
|
||||||
# Function: Romeve a key in the json field of *_custom_attributes_values.values
|
# Function: Romeve a key in the json field of *_custom_attributes_values.values
|
||||||
migrations.RunSQL(
|
migrations.RunSQL(
|
||||||
"""
|
"""
|
||||||
CREATE OR REPLACE FUNCTION "clean_key_in_custom_attributes_values"()
|
CREATE OR REPLACE FUNCTION "clean_key_in_custom_attributes_values"()
|
||||||
RETURNS trigger
|
RETURNS trigger
|
||||||
AS $clean_key_in_custom_attributes_values$
|
AS $clean_key_in_custom_attributes_values$
|
||||||
DECLARE
|
DECLARE
|
||||||
key text;
|
key text;
|
||||||
project_id int;
|
project_id int;
|
||||||
object_id int;
|
object_id int;
|
||||||
attribute text;
|
attribute text;
|
||||||
tablename text;
|
tablename text;
|
||||||
custom_attributes_tablename text;
|
custom_attributes_tablename text;
|
||||||
BEGIN
|
BEGIN
|
||||||
key := OLD.id::text;
|
key := OLD.id::text;
|
||||||
project_id := OLD.project_id;
|
project_id := OLD.project_id;
|
||||||
attribute := TG_ARGV[0]::text;
|
attribute := TG_ARGV[0]::text;
|
||||||
tablename := TG_ARGV[1]::text;
|
tablename := TG_ARGV[1]::text;
|
||||||
custom_attributes_tablename := TG_ARGV[2]::text;
|
custom_attributes_tablename := TG_ARGV[2]::text;
|
||||||
|
|
||||||
EXECUTE 'UPDATE ' || quote_ident(custom_attributes_tablename) || '
|
|
||||||
SET attributes_values = json_object_delete_keys(attributes_values, ' || quote_literal(key) || ')
|
|
||||||
FROM ' || quote_ident(tablename) || '
|
|
||||||
WHERE ' || quote_ident(tablename) || '.project_id = ' || project_id || '
|
|
||||||
AND ' || quote_ident(custom_attributes_tablename) || '.' || quote_ident(attribute) || ' = ' || quote_ident(tablename) || '.id';
|
|
||||||
RETURN NULL;
|
|
||||||
END; $clean_key_in_custom_attributes_values$
|
|
||||||
LANGUAGE plpgsql;
|
|
||||||
|
|
||||||
|
EXECUTE 'UPDATE ' || quote_ident(custom_attributes_tablename) || '
|
||||||
|
SET attributes_values = json_object_delete_keys(attributes_values, ' || quote_literal(key) || ')
|
||||||
|
FROM ' || quote_ident(tablename) || '
|
||||||
|
WHERE ' || quote_ident(tablename) || '.project_id = ' || project_id || '
|
||||||
|
AND ' || quote_ident(custom_attributes_tablename) || '.' || quote_ident(attribute) || ' = ' || quote_ident(tablename) || '.id';
|
||||||
|
RETURN NULL;
|
||||||
|
END; $clean_key_in_custom_attributes_values$
|
||||||
|
LANGUAGE plpgsql;
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -66,13 +66,14 @@ class Migration(migrations.Migration):
|
||||||
migrations.RunSQL(
|
migrations.RunSQL(
|
||||||
"""
|
"""
|
||||||
DROP TRIGGER IF EXISTS "update_userstorycustomvalues_after_remove_userstorycustomattribute"
|
DROP TRIGGER IF EXISTS "update_userstorycustomvalues_after_remove_userstorycustomattribute"
|
||||||
ON custom_attributes_userstorycustomattribute
|
ON custom_attributes_userstorycustomattribute
|
||||||
CASCADE;
|
CASCADE;
|
||||||
|
|
||||||
CREATE TRIGGER "update_userstorycustomvalues_after_remove_userstorycustomattribute"
|
CREATE TRIGGER "update_userstorycustomvalues_after_remove_userstorycustomattribute"
|
||||||
AFTER DELETE ON custom_attributes_userstorycustomattribute
|
AFTER DELETE ON custom_attributes_userstorycustomattribute
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE PROCEDURE clean_key_in_custom_attributes_values('user_story_id', 'userstories_userstory', 'custom_attributes_userstorycustomattributesvalues');
|
EXECUTE PROCEDURE clean_key_in_custom_attributes_values('user_story_id', 'userstories_userstory',
|
||||||
|
'custom_attributes_userstorycustomattributesvalues');
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -80,13 +81,14 @@ class Migration(migrations.Migration):
|
||||||
migrations.RunSQL(
|
migrations.RunSQL(
|
||||||
"""
|
"""
|
||||||
DROP TRIGGER IF EXISTS "update_taskcustomvalues_after_remove_taskcustomattribute"
|
DROP TRIGGER IF EXISTS "update_taskcustomvalues_after_remove_taskcustomattribute"
|
||||||
ON custom_attributes_taskcustomattribute
|
ON custom_attributes_taskcustomattribute
|
||||||
CASCADE;
|
CASCADE;
|
||||||
|
|
||||||
CREATE TRIGGER "update_taskcustomvalues_after_remove_taskcustomattribute"
|
CREATE TRIGGER "update_taskcustomvalues_after_remove_taskcustomattribute"
|
||||||
AFTER DELETE ON custom_attributes_taskcustomattribute
|
AFTER DELETE ON custom_attributes_taskcustomattribute
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE PROCEDURE clean_key_in_custom_attributes_values('task_id', 'tasks_task', 'custom_attributes_taskcustomattributesvalues');
|
EXECUTE PROCEDURE clean_key_in_custom_attributes_values('task_id', 'tasks_task',
|
||||||
|
'custom_attributes_taskcustomattributesvalues');
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -94,13 +96,14 @@ class Migration(migrations.Migration):
|
||||||
migrations.RunSQL(
|
migrations.RunSQL(
|
||||||
"""
|
"""
|
||||||
DROP TRIGGER IF EXISTS "update_issuecustomvalues_after_remove_issuecustomattribute"
|
DROP TRIGGER IF EXISTS "update_issuecustomvalues_after_remove_issuecustomattribute"
|
||||||
ON custom_attributes_issuecustomattribute
|
ON custom_attributes_issuecustomattribute
|
||||||
CASCADE;
|
CASCADE;
|
||||||
|
|
||||||
CREATE TRIGGER "update_issuecustomvalues_after_remove_issuecustomattribute"
|
CREATE TRIGGER "update_issuecustomvalues_after_remove_issuecustomattribute"
|
||||||
AFTER DELETE ON custom_attributes_issuecustomattribute
|
AFTER DELETE ON custom_attributes_issuecustomattribute
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE PROCEDURE clean_key_in_custom_attributes_values('issue_id', 'issues_issue', 'custom_attributes_issuecustomattributesvalues');
|
EXECUTE PROCEDURE clean_key_in_custom_attributes_values('issue_id', 'issues_issue',
|
||||||
|
'custom_attributes_issuecustomattributesvalues');
|
||||||
"""
|
"""
|
||||||
),
|
),
|
||||||
migrations.AlterIndexTogether(
|
migrations.AlterIndexTogether(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Generated by Django 1.9.2 on 2016-06-30 08:49
|
# Generated by Django 1.9.2 on 2016-07-28 10:02
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -11,12 +11,13 @@ import django_pgjson.fields
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('epics', '0001_initial'),
|
('epics', '0002_epic_color'),
|
||||||
('projects', '0049_auto_20160629_1443'),
|
('projects', '0050_project_epics_csv_uuid'),
|
||||||
('custom_attributes', '0007_auto_20160208_1751'),
|
('custom_attributes', '0008_auto_20160728_0540'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
# Change some verbose names
|
||||||
migrations.AlterModelOptions(
|
migrations.AlterModelOptions(
|
||||||
name='issuecustomattributesvalues',
|
name='issuecustomattributesvalues',
|
||||||
options={'ordering': ['id'], 'verbose_name': 'issue custom attributes values', 'verbose_name_plural': 'issue custom attributes values'},
|
options={'ordering': ['id'], 'verbose_name': 'issue custom attributes values', 'verbose_name_plural': 'issue custom attributes values'},
|
||||||
|
@ -29,7 +30,7 @@ class Migration(migrations.Migration):
|
||||||
name='userstorycustomattributesvalues',
|
name='userstorycustomattributesvalues',
|
||||||
options={'ordering': ['id'], 'verbose_name': 'user story custom attributes values', 'verbose_name_plural': 'user story custom attributes values'},
|
options={'ordering': ['id'], 'verbose_name': 'user story custom attributes values', 'verbose_name_plural': 'user story custom attributes values'},
|
||||||
),
|
),
|
||||||
|
# Custom attributes for epics
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='EpicCustomAttribute',
|
name='EpicCustomAttribute',
|
||||||
fields=[
|
fields=[
|
||||||
|
@ -43,10 +44,10 @@ class Migration(migrations.Migration):
|
||||||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='epiccustomattributes', to='projects.Project', verbose_name='project')),
|
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='epiccustomattributes', to='projects.Project', verbose_name='project')),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name_plural': 'epic custom attributes',
|
|
||||||
'verbose_name': 'epic custom attribute',
|
'verbose_name': 'epic custom attribute',
|
||||||
'abstract': False,
|
'abstract': False,
|
||||||
'ordering': ['project', 'order', 'name'],
|
'ordering': ['project', 'order', 'name'],
|
||||||
|
'verbose_name_plural': 'epic custom attributes',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -58,24 +59,27 @@ class Migration(migrations.Migration):
|
||||||
('epic', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='custom_attributes_values', to='epics.Epic', verbose_name='epic')),
|
('epic', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='custom_attributes_values', to='epics.Epic', verbose_name='epic')),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name_plural': 'epic custom attributes values',
|
|
||||||
'verbose_name': 'epic custom attributes values',
|
|
||||||
'abstract': False,
|
'abstract': False,
|
||||||
|
'verbose_name': 'epic custom attributes values',
|
||||||
'ordering': ['id'],
|
'ordering': ['id'],
|
||||||
|
'verbose_name_plural': 'epic custom attributes values',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
migrations.AlterIndexTogether(
|
||||||
|
name='epiccustomattributesvalues',
|
||||||
|
index_together=set([('epic',)]),
|
||||||
|
),
|
||||||
migrations.AlterUniqueTogether(
|
migrations.AlterUniqueTogether(
|
||||||
name='epiccustomattribute',
|
name='epiccustomattribute',
|
||||||
unique_together=set([('project', 'name')]),
|
unique_together=set([('project', 'name')]),
|
||||||
),
|
),
|
||||||
|
|
||||||
# Trigger: Clean epiccustomattributes values before remove a epiccustomattribute
|
|
||||||
migrations.RunSQL(
|
migrations.RunSQL(
|
||||||
"""
|
"""
|
||||||
CREATE TRIGGER "update_epiccustomvalues_after_remove_epiccustomattribute"
|
CREATE TRIGGER "update_epiccustomvalues_after_remove_epiccustomattribute"
|
||||||
AFTER DELETE ON custom_attributes_epiccustomattribute
|
AFTER DELETE ON custom_attributes_epiccustomattribute
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE PROCEDURE clean_key_in_custom_attributes_values('custom_attributes_epiccustomattributesvalues');
|
EXECUTE PROCEDURE clean_key_in_custom_attributes_values('epic_id', 'epics_epic',
|
||||||
|
'custom_attributes_epiccustomattributesvalues');
|
||||||
""",
|
""",
|
||||||
reverse_sql="""DROP TRIGGER IF EXISTS "update_epiccustomvalues_after_remove_epiccustomattribute"
|
reverse_sql="""DROP TRIGGER IF EXISTS "update_epiccustomvalues_after_remove_epiccustomattribute"
|
||||||
ON custom_attributes_epiccustomattribute
|
ON custom_attributes_epiccustomattribute
|
|
@ -106,6 +106,7 @@ class EpicCustomAttributesValues(AbstractCustomAttributesValues):
|
||||||
class Meta(AbstractCustomAttributesValues.Meta):
|
class Meta(AbstractCustomAttributesValues.Meta):
|
||||||
verbose_name = "epic custom attributes values"
|
verbose_name = "epic custom attributes values"
|
||||||
verbose_name_plural = "epic custom attributes values"
|
verbose_name_plural = "epic custom attributes values"
|
||||||
|
index_together = [("epic",)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def project(self):
|
def project(self):
|
||||||
|
|
Loading…
Reference in New Issue