Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

feat: publish revision tables #282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion scripts/linz-bde-schema-publish.bash
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ BEGIN
'Schema bde does not exist, '
'run linz-bde-schema-load ?';
END IF;

IF NOT EXISTS ( SELECT 1 FROM pg_catalog.pg_publication
WHERE pubname = 'all_bde' )
THEN
CREATE PUBLICATION all_bde;
END IF;

ALTER PUBLICATION all_bde OWNER TO bde_dba;

FOR v_table IN SELECT c.relname from pg_class c, pg_namespace n
WHERE n.nspname = 'bde' and c.relnamespace = n.oid
WHERE n.nspname = 'bde' AND c.relnamespace = n.oid
AND c.relkind = 'r' AND c.relname NOT IN (
SELECT tablename FROM pg_catalog.pg_publication_tables
WHERE pubname = 'all_bde' AND schemaname = 'bde'
Expand All @@ -66,7 +68,36 @@ BEGIN
v_table);
END LOOP;

IF NOT EXISTS ( SELECT 1 FROM pg_catalog.pg_namespace
WHERE nspname = 'table_version')
THEN
RAISE EXCEPTION
'Schema table_version does not exist, '
'have you enabled table versioning?';
END IF;

IF NOT EXISTS ( SELECT 1 FROM pg_catalog.pg_publication
WHERE pubname = 'all_bde_versions' )
THEN
CREATE PUBLICATION all_bde_versions;
END IF;

ALTER PUBLICATION all_bde_versions OWNER TO bde_dba;

FOR v_table IN SELECT c.relname from pg_class c, pg_namespace n
WHERE n.nspname = 'table_version' AND c.relnamespace = n.oid
AND c.relkind = 'r' AND c.relname SIMILAR TO 'bde_(crs|cbe)_%'
AND c.relname NOT IN (
SELECT tablename FROM pg_catalog.pg_publication_tables
WHERE pubname = 'all_bde_versions' AND schemaname = 'table_version'
)
LOOP
EXECUTE format('ALTER PUBLICATION all_bde_versions ADD TABLE table_version.%I',
v_table);
END LOOP;

RAISE INFO 'Publication "all_bde" ready';
RAISE INFO 'Publication "all_bde_versions" ready';

END;
\$PUBLICATION\$;
Expand Down