CREATE EXTENSION IF NOT EXISTS postgres_fdw;
-CREATE SERVER pdns_master FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'systemshare.pixelpark.com', dbname 'pdns');
+CREATE SERVER pdns_master
+ FOREIGN DATA WRAPPER postgres_fdw
+ OPTIONS (host 'systemshare.pixelpark.com', dbname 'pdns');
ALTER SERVER pdns_master OWNER TO pdns_local;
-CREATE USER MAPPING FOR pdns_local SERVER pdns_master OPTIONS (user 'pdns_local', password 'Neingeichee(ghahn7ah');
+CREATE USER MAPPING FOR pdns_local
+ SERVER pdns_master
+ OPTIONS (user 'pdns_local', password 'Neingeichee(ghahn7ah');
CREATE SCHEMA IF NOT EXISTS pdns;
ALTER SCHEMA pdns OWNER TO pdns_local;
+
+COMMIT;
+
+BEGIN WORK;
+
+-- Execute as User pdns_local !!!
IMPORT FOREIGN SCHEMA public FROM SERVER pdns_master INTO pdns;
COMMIT;
COMMIT;
+-- ----------------------------------------------------------------------
+
+\connect pdns_public
+
+BEGIN WORK;
+
+CREATE EXTENSION IF NOT EXISTS postgres_fdw;
+
+CREATE SERVER pdns_master
+ FOREIGN DATA WRAPPER postgres_fdw
+ OPTIONS (host 'systemshare.pixelpark.com', dbname 'pdns');
+ALTER SERVER pdns_master OWNER TO pdns_public;
+CREATE USER MAPPING FOR pdns_public
+ SERVER pdns_master
+ OPTIONS (user 'pdns_public', password 'ahr7die3gee]s4vahCoh');
+
+CREATE SCHEMA IF NOT EXISTS pdns;
+ALTER SCHEMA pdns OWNER TO pdns_public;
+
+COMMIT;
+
+BEGIN WORK;
+
+-- Execute as User pdns_public !!!
+IMPORT FOREIGN SCHEMA public FROM SERVER pdns_master INTO pdns;
+
+COMMIT;
+
+-- ----------------
+
+BEGIN WORK;
+
+CREATE or REPLACE VIEW public.domains AS
+SELECT id, name, master, last_check, type, notified_serial, account
+ FROM pdns.domains
+ WHERE account IS NULL OR account !~* '.*(lo[ck]al|privat|intern).*'
+ ORDER BY name;
+
+ALTER TABLE IF EXISTS public.domains OWNER TO pdns_local;
+
+COMMIT;
+
-- vim: list