From 37aacc7da9e9876ade32b4026e49207a05aa4dc4 Mon Sep 17 00:00:00 2001 From: solopiu Date: Thu, 16 Dec 2021 18:29:57 +0100 Subject: [PATCH] created changes view --- .../20211216172918_create_changes_view.down.sql | 1 + .../20211216172918_create_changes_view.up.sql | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 configs/migrations/redshift/20211216172918_create_changes_view.down.sql create mode 100644 configs/migrations/redshift/20211216172918_create_changes_view.up.sql diff --git a/configs/migrations/redshift/20211216172918_create_changes_view.down.sql b/configs/migrations/redshift/20211216172918_create_changes_view.down.sql new file mode 100644 index 0000000..38d15e3 --- /dev/null +++ b/configs/migrations/redshift/20211216172918_create_changes_view.down.sql @@ -0,0 +1 @@ +DROP VIEW watchops.changes; diff --git a/configs/migrations/redshift/20211216172918_create_changes_view.up.sql b/configs/migrations/redshift/20211216172918_create_changes_view.up.sql new file mode 100644 index 0000000..da58e69 --- /dev/null +++ b/configs/migrations/redshift/20211216172918_create_changes_view.up.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE VIEW watchops.changes AS ( + WITH all_commits AS + ( + SELECT source, event_type, json_parse(json_serialize(metadata)) AS metadata + FROM watchops.events_raw + WHERE event_type = 'push' + and json_serialize(metadata) LIKE '%"commits":[%' + ), + commit AS + ( + SELECT index, i.source, i.event_type, element.timestamp AS time_created, element.id AS change_id + FROM all_commits AS i, i.metadata.commits AS element AT index + ) + SELECT source, event_type, change_id, date_trunc('second', TO_TIMESTAMP(CAST(time_created AS VARCHAR), 'YYYY-MM-DDTHH:MI:SS')) AS time_created + FROM commit +) +