diff --git a/infrastructure/terraform/components/reporting/null_resource_request_item_plan_status_table.tf b/infrastructure/terraform/components/reporting/null_resource_request_item_plan_status_table.tf index 594d05e2..994bbd77 100644 --- a/infrastructure/terraform/components/reporting/null_resource_request_item_plan_status_table.tf +++ b/infrastructure/terraform/components/reporting/null_resource_request_item_plan_status_table.tf @@ -60,3 +60,19 @@ resource "null_resource" "request_item_plan_status_recipientcontactid_column" { depends_on = [null_resource.request_item_plan_status_ordernumber_column] } + +resource "null_resource" "request_item_plan_status_templateid_column" { + triggers = { + always_run = timestamp() + } + provisioner "local-exec" { + command = <)[LOWER(supplier)] AS templateid, CAST("$classification".timestamp AS BIGINT) AS timestamp FROM ${source_table} WHERE (sk LIKE 'REQUEST_ITEM_PLAN#%') AND @@ -63,6 +64,7 @@ WHEN MATCHED AND (source.timestamp > target.timestamp) THEN UPDATE SET channeltype = source.channeltype, ordernumber = source.ordernumber, recipientcontactid = source.recipientcontactid, + templateid = source.templateid, timestamp = source.timestamp WHEN NOT MATCHED THEN INSERT ( clientid, @@ -85,6 +87,7 @@ WHEN NOT MATCHED THEN INSERT ( channeltype, ordernumber, recipientcontactid, + templateid, timestamp ) VALUES ( @@ -108,5 +111,6 @@ VALUES ( source.channeltype, source.ordernumber, source.recipientcontactid, + source.templateid, source.timestamp ) diff --git a/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_batch_report.sql b/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_batch_report.sql index 1dcd8cfa..a6420042 100644 --- a/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_batch_report.sql +++ b/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_batch_report.sql @@ -15,6 +15,7 @@ SELECT requestitemplanstatus, communicationtype, channeltype, - requestitemplanfailedreason + requestitemplanfailedreason, + templateid FROM completed_comms WHERE clientid = ? AND requestid = ? diff --git a/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_comms_report.sql b/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_comms_report.sql index 112aebac..0cb6798b 100644 --- a/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_comms_report.sql +++ b/infrastructure/terraform/components/reporting/scripts/sql/reports/completed_comms_report.sql @@ -15,7 +15,8 @@ SELECT requestitemplanstatus, communicationtype, channeltype, - requestitemplanfailedreason + requestitemplanfailedreason, + templateid FROM completed_comms WHERE clientid = ? AND diff --git a/infrastructure/terraform/components/reporting/scripts/sql/tables/request_item_plan_status.sql b/infrastructure/terraform/components/reporting/scripts/sql/tables/request_item_plan_status.sql index b8167ea3..751aa1c0 100644 --- a/infrastructure/terraform/components/reporting/scripts/sql/tables/request_item_plan_status.sql +++ b/infrastructure/terraform/components/reporting/scripts/sql/tables/request_item_plan_status.sql @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS ${table_name} ( channeltype string, ordernumber int, recipientcontactid string, + templateid string, timestamp bigint ) PARTITIONED BY (bucket(32, clientid), month(createdtime), month(completedtime)) diff --git a/infrastructure/terraform/components/reporting/scripts/sql/views/completed_comms.sql b/infrastructure/terraform/components/reporting/scripts/sql/views/completed_comms.sql index 47fc3b96..ae1e2178 100644 --- a/infrastructure/terraform/components/reporting/scripts/sql/views/completed_comms.sql +++ b/infrastructure/terraform/components/reporting/scripts/sql/views/completed_comms.sql @@ -17,7 +17,8 @@ SELECT rip.status as requestitemplanstatus, rip.communicationtype as communicationtype, rip.channeltype as channeltype, - rip.failedreason as requestitemplanfailedreason + rip.failedreason as requestitemplanfailedreason, + rip.templateid as templateid FROM request_item_status ri LEFT OUTER JOIN request_item_plan_status rip ON ri.requestitemid = rip.requestitemid AND