CREATE DATABASE pdns WITH ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
CREATE DATABASE pdnsadm WITH ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
+CREATE DATABASE pdns_local WITH ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
+CREATE DATABASE pdns_public WITH ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
+
BEGIN WORK;
+CREATE ROLE dns
+ NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
+COMMENT ON ROLE dns IS 'All DNS related users';
+
CREATE USER pdns WITH PASSWORD 'oo?fah7gai7X';
+COMMENT ON ROLE pdns IS 'User for PowerDNS';
+GRANT dns TO pdns;
GRANT ALL ON DATABASE "pdns" TO pdns;
ALTER DATABASE pdns OWNER TO pdns;
CREATE USER pdnsadm WITH PASSWORD 'Eig}o3ojoh@w';
+COMMENT ON ROLE pdnsadm IS 'User for different PowerDNS GUIs';
+GRANT dns TO pdnsadm;
GRANT ALL ON DATABASE "pdnsadm" TO pdnsadm;
ALTER DATABASE pdnsadm OWNER TO pdnsadm;
+CREATE USER pdns_local WITH PASSWORD 'Neingeichee(ghahn7ah';
+COMMENT ON ROLE pdns IS 'User for local PowerDNS';
+GRANT dns TO pdns_local;
+GRANT ALL ON DATABASE "pdns_local" TO pdns_local;
+ALTER DATABASE pdns_local OWNER TO pdns_local;
+
+CREATE USER pdns_public WITH PASSWORD 'ahr7die3gee]s4vahCoh';
+COMMENT ON ROLE pdns IS 'User for public PowerDNS';
+GRANT dns TO pdns_public;
+GRANT ALL ON DATABASE "pdns_public" TO pdns_public;
+ALTER DATABASE pdns_public OWNER TO pdns_public;
+
COMMIT;
+-- ----------------------------------------------------------------------
+
BEGIN WORK;
+-- ----------------
CREATE TABLE domains (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
ALTER TABLE IF EXISTS domains OWNER TO pdns;
ALTER SEQUENCE IF EXISTS domains_id_seq OWNER TO pdns;
+GRANT SELECT ON TABLE domains TO dns;
+
+-- ----------------
CREATE TABLE records (
id SERIAL PRIMARY KEY,
domain_id INT DEFAULT NULL,
ALTER TABLE IF EXISTS records OWNER TO pdns;
ALTER SEQUENCE IF EXISTS records_id_seq OWNER TO pdns;
+GRANT SELECT ON TABLE records TO dns;
+
+-- ----------------
CREATE TABLE supermasters (
ip INET NOT NULL,
nameserver VARCHAR(255) NOT NULL,
ALTER TABLE IF EXISTS supermasters OWNER TO pdns;
+GRANT SELECT ON TABLE supermasters TO dns;
+
+-- ----------------
CREATE TABLE comments (
id SERIAL PRIMARY KEY,
domain_id INT NOT NULL,
ALTER TABLE IF EXISTS comments OWNER TO pdns;
ALTER SEQUENCE IF EXISTS comments_id_seq OWNER TO pdns;
+GRANT SELECT ON TABLE comments TO dns;
+
+-- ----------------
CREATE TABLE domainmetadata (
id SERIAL PRIMARY KEY,
domain_id INT REFERENCES domains(id) ON DELETE CASCADE,
ALTER TABLE IF EXISTS domainmetadata OWNER TO pdns;
ALTER SEQUENCE IF EXISTS domainmetadata_id_seq OWNER TO pdns;
+GRANT SELECT ON TABLE domainmetadata TO dns;
+
+-- ----------------
CREATE TABLE cryptokeys (
id SERIAL PRIMARY KEY,
domain_id INT REFERENCES domains(id) ON DELETE CASCADE,
ALTER TABLE IF EXISTS cryptokeys OWNER TO pdns;
ALTER SEQUENCE IF EXISTS cryptokeys_id_seq OWNER TO pdns;
+-- ----------------
CREATE TABLE tsigkeys (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
ALTER TABLE IF EXISTS tsigkeys OWNER TO pdns;
ALTER SEQUENCE IF EXISTS tsigkeys_id_seq OWNER TO pdns;
+GRANT SELECT ON TABLE tsigkeys TO dns;
+
COMMIT;