commit
0398544a51
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
||||
.dbeaver-data-sources.xml
|
||||
.project
|
||||
Scripts/
|
||||
*.log
|
||||
*.swp
|
||||
|
@ -7,8 +7,10 @@
|
||||
"{Post Date}",
|
||||
"{Description}"
|
||||
],
|
||||
"schemas": {
|
||||
"default": [
|
||||
"schemas": [
|
||||
{
|
||||
"name": "default",
|
||||
"columns": [
|
||||
{
|
||||
"path": "{Trans. Date}",
|
||||
"type": "date",
|
||||
@ -34,8 +36,11 @@
|
||||
"type": "text",
|
||||
"column_name": "Category"
|
||||
}
|
||||
],
|
||||
"mapped": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mapped",
|
||||
"columns": [
|
||||
{
|
||||
"path": "{Trans. Date}",
|
||||
"type": "date",
|
||||
@ -73,4 +78,5 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
30
database/upgrade_scripts/001.extract_schemas.sql
Normal file
30
database/upgrade_scripts/001.extract_schemas.sql
Normal file
@ -0,0 +1,30 @@
|
||||
WITH
|
||||
mod AS (
|
||||
SELECT
|
||||
srce
|
||||
,jsonb_pretty(defn) orig
|
||||
,(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)
|
||||
)
|
||||
) rebuild
|
||||
FROM
|
||||
tps.srce
|
||||
LEFT JOIN LATERAL jsonb_each(defn->'schemas') WITH ORDINALITY je(k,v, rn) ON TRUE
|
||||
GROUP BY
|
||||
srce
|
||||
,defn
|
||||
)
|
||||
UPDATE
|
||||
tps.srce s
|
||||
SET
|
||||
defn = rebuild
|
||||
FROM
|
||||
mod
|
||||
WHERE
|
||||
mod.srce = s.srce
|
Loading…
Reference in New Issue
Block a user