extrapolate a view from schema
This commit is contained in:
parent
eb8da0f6c5
commit
80406a2dc6
@ -11,7 +11,7 @@ COMMENT ON SCHEMA tps IS 'third party source views';
|
|||||||
|
|
||||||
DROP USER IF EXISTS api;
|
DROP USER IF EXISTS api;
|
||||||
|
|
||||||
CREATE USER api WITH
|
CREATE ROLE api WITH
|
||||||
LOGIN
|
LOGIN
|
||||||
NOSUPERUSER
|
NOSUPERUSER
|
||||||
NOCREATEDB
|
NOCREATEDB
|
||||||
@ -23,6 +23,9 @@ CREATE USER api WITH
|
|||||||
|
|
||||||
-----need to setup all database objects and then grant priveledges to api----------------------------------------------------------------------------
|
-----need to setup all database objects and then grant priveledges to api----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
--grant schema USAGE
|
||||||
|
GRANT USAGE ON SCHEMA tps TO api;
|
||||||
|
|
||||||
--grant current table privledges
|
--grant current table privledges
|
||||||
GRANT SELECT, UPDATE, INSERT, DELETE ON ALL TABLES IN SCHEMA tps TO api;
|
GRANT SELECT, UPDATE, INSERT, DELETE ON ALL TABLES IN SCHEMA tps TO api;
|
||||||
GRANT SELECT, UPDATE, INSERT, DELETE ON ALL TABLES IN SCHEMA tpsv TO api;
|
GRANT SELECT, UPDATE, INSERT, DELETE ON ALL TABLES IN SCHEMA tpsv TO api;
|
||||||
|
28
interface/source_maint/srce_build_view.sql
Normal file
28
interface/source_maint/srce_build_view.sql
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
DO
|
||||||
|
$f$
|
||||||
|
DECLARE
|
||||||
|
_path text[];
|
||||||
|
_srce text;
|
||||||
|
_sql text;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
_path:= '{schemas,default}'::text[];
|
||||||
|
_srce:= 'dcard';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
'CREATE VIEW tpsv.'||_srce||'_'||_path[2]||' AS SELECT '||string_agg('(rec#>>'''||r.PATH::text||''')::'||r.type||' AS "'||r.column_name||'"',', ')||' FROM tps.trans WHERE srce = '''||_srce||''''
|
||||||
|
INTO
|
||||||
|
_sql
|
||||||
|
FROM
|
||||||
|
tps.srce
|
||||||
|
JOIN LATERAL jsonb_array_elements(defn#>_path) ae(v) ON TRUE
|
||||||
|
JOIN LATERAL jsonb_to_record (ae.v) AS r(PATH text[], "type" text, column_name text) ON TRUE
|
||||||
|
WHERE
|
||||||
|
srce = _srce
|
||||||
|
GROUP BY
|
||||||
|
srce.srce;
|
||||||
|
|
||||||
|
RAISE NOTICE '%',_sql;
|
||||||
|
|
||||||
|
END
|
||||||
|
$f$;
|
@ -1,3 +1,5 @@
|
|||||||
|
--need to build history (trigger)?
|
||||||
|
|
||||||
DO $f$
|
DO $f$
|
||||||
|
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -54,49 +56,15 @@ BEGIN
|
|||||||
$$
|
$$
|
||||||
INTO
|
INTO
|
||||||
_defn;
|
_defn;
|
||||||
|
|
||||||
/*
|
|
||||||
validate schema? should not need validation if created by ui
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
-------extract current source schema for compare--------------------------
|
|
||||||
SELECT
|
|
||||||
defn#>'{schemas,default}'
|
|
||||||
INTO
|
|
||||||
_cur_sch
|
|
||||||
FROM
|
|
||||||
tps.srce
|
|
||||||
WHERE
|
|
||||||
srce = _defn->>'name';
|
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------
|
|
||||||
do schema validation
|
|
||||||
---------------------------------------------------------*/
|
|
||||||
|
|
||||||
-------------------insert definition----------------------------------------
|
-------------------insert definition----------------------------------------
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
tps.srce
|
tps.srce (srce, defn)
|
||||||
SELECT
|
SELECT
|
||||||
_defn->>'name', _defn
|
_defn->>'name', _defn
|
||||||
ON CONFLICT ON CONSTRAINT srce_pkey DO UPDATE
|
ON CONFLICT ON CONSTRAINT srce_pkey DO UPDATE
|
||||||
SET
|
SET
|
||||||
defn = _defn;
|
defn = _defn;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_message =
|
|
||||||
$$
|
|
||||||
{
|
|
||||||
"message": "definition set",
|
|
||||||
"status": "success"
|
|
||||||
}
|
|
||||||
$$: :jsonb;
|
|
||||||
return _message;
|
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$f$
|
$f$
|
||||||
|
Loading…
Reference in New Issue
Block a user