Skip to content

Commit

Permalink
Updated names
Browse files Browse the repository at this point in the history
  • Loading branch information
Cali0707 committed Jun 21, 2022
1 parent 11a7055 commit ee9dc2e
Showing 1 changed file with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
exports.up = async function (knex) {
return await knex.raw(`
with user_name_type as (
select ('{'||index-1||',name}')::text[] as path
from notification n, jsonb_array_elements(n.variables) with ordinality arr(variable, index)
where variable->>'name' = 'assignee' and body @> '{"translation_key": "NOTIFICATION.TASK_ASSIGNED.BODY"}'
) update notification set variables = jsonb_set(variables, user_name_type.path, '"assigner"', false)
from user_name_type
where notification.variables @> '[{"name": "assignee"}]' and body @> '{"translation_key": "NOTIFICATION.TASK_ASSIGNED.BODY"}';
with subquery as (
select ('{'||index-1||',name}')::text[] as name_path, ('{'||index-1||',value}')::text[] as value_path, n.notification_id,
(select concat('"', first_name, ' ', last_name, '"')::jsonb from users u where u.user_id = (select t.updated_by_user_id from task t where t.task_id = (select n.ref->'entity'->>'id')::integer)) as user_name
from notification n, jsonb_array_elements(n.variables) with ordinality arr(variable, index)
where variable->>'name' = 'assignee' and body @> '{"translation_key": "NOTIFICATION.TASK_ASSIGNED.BODY"}'
) update notification set variables = jsonb_set(
jsonb_set(variables, subquery.name_path, '"assigner"', false),
subquery.value_path,
subquery.user_name,
false
)
from subquery
where notification.notification_id = subquery.notification_id;
`);
};

exports.down = async function (knex) {
return await knex.raw(`
with user_name_type as (
select ('{'||index-1||',name}')::text[] as path
from notification n, jsonb_array_elements(n.variables) with ordinality arr(variable, index)
where variable->>'name' = 'assigner' and body @> '{"translation_key": "NOTIFICATION.TASK_ASSIGNED.BODY"}'
) update notification set variables = jsonb_set(variables, user_name_type.path, '"assignee"', false)
from user_name_type
where notification.variables @> '[{"name": "assigner"}]' and body @> '{"translation_key": "NOTIFICATION.TASK_ASSIGNED.BODY"}';
with subquery as (
select ('{'||index-1||',name}')::text[] as name_path, ('{'||index-1||',value}')::text[] as value_path, n.notification_id,
(select concat('"', first_name, ' ', last_name, '"')::jsonb from users u where u.user_id = (select t.assignee_user_id from task t where t.task_id = (select n.ref->'entity'->>'id')::integer)) as user_name
from notification n, jsonb_array_elements(n.variables) with ordinality arr(variable, index)
where variable->>'name' = 'assigner' and body @> '{"translation_key": "NOTIFICATION.TASK_ASSIGNED.BODY"}'
) update notification set variables = jsonb_set(
jsonb_set(variables, subquery.name_path, '"assignee"', false),
subquery.value_path,
subquery.user_name,
false
)
from subquery
where notification.notification_id = subquery.notification_id;
`);
};

0 comments on commit ee9dc2e

Please # to comment.