From 69dbc7742b7cc617a8f1cade5f478cf851b85e45 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Sun, 2 Dec 2018 00:59:00 -0500 Subject: [PATCH] work on upgrade query to adjust schema and leave sources in place --- .../upgrade_scripts/001.extract_schemas.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 database/upgrade_scripts/001.extract_schemas.sql diff --git a/database/upgrade_scripts/001.extract_schemas.sql b/database/upgrade_scripts/001.extract_schemas.sql new file mode 100644 index 0000000..39a01a7 --- /dev/null +++ b/database/upgrade_scripts/001.extract_schemas.sql @@ -0,0 +1,19 @@ +SELECT + srce + ,jsonb_pretty(defn) + ,jsonb_pretty((defn - 'schemas')|| + --rebuild the schemas key value from below + jsonb_build_object( + 'schemas' + --aggregate all the new key values for a single soure + ,jsonb_agg( + --combine a new key 'name' with the columns for that name + jsonb_build_object('name',k)||jsonb_build_object('columns',v) + ) + )) +FROM + tps.srce + LEFT JOIN LATERAL jsonb_each(defn->'schemas') WITH ORDINALITY je(k,v, rn) ON TRUE +GROUP BY + srce + ,defn \ No newline at end of file