[50] | 1 | -- these lines could be run as a superuser. alter database name, username, password, group as appropriate.
|
---|
| 2 | -- make sure to alter dnsdb.conf to match
|
---|
| 3 | -- CREATE GROUP dnsdb;
|
---|
| 4 | -- CREATE USER dnsdb WITH UNENCRYPTED PASSWORD 'secret' IN GROUP dnsdb;
|
---|
| 5 | -- CREATE DATABASE dnsdb OWNED BY dnsdb;
|
---|
| 6 | -- SET SESSION AUTHORIZATION 'dnsdb';
|
---|
| 7 |
|
---|
| 8 | -- tabledefs and preloaded data bits
|
---|
| 9 | CREATE TABLE groups (
|
---|
| 10 | group_id serial NOT NULL,
|
---|
| 11 | parent_group_id integer DEFAULT 1 NOT NULL,
|
---|
| 12 | group_name character varying(255) DEFAULT ''::character varying NOT NULL
|
---|
| 13 | );
|
---|
| 14 |
|
---|
| 15 | -- Provide a basic default group
|
---|
| 16 | COPY groups (group_id, parent_group_id, group_name) FROM stdin;
|
---|
| 17 | 1 1 default
|
---|
| 18 | \.
|
---|
| 19 |
|
---|
| 20 | CREATE TABLE domains (
|
---|
| 21 | domain_id serial NOT NULL,
|
---|
| 22 | "domain" character varying(80) NOT NULL,
|
---|
| 23 | group_id integer DEFAULT 1 NOT NULL,
|
---|
| 24 | description character varying(255) DEFAULT ''::character varying NOT NULL,
|
---|
| 25 | status integer DEFAULT 1 NOT NULL,
|
---|
| 26 | zserial integer,
|
---|
| 27 | sertype character(1) DEFAULT 'D'::bpchar
|
---|
| 28 | );
|
---|
| 29 |
|
---|
| 30 | CREATE TABLE default_records (
|
---|
| 31 | record_id serial NOT NULL,
|
---|
| 32 | group_id integer DEFAULT 1 NOT NULL,
|
---|
| 33 | host character varying(100) DEFAULT ''::character varying NOT NULL,
|
---|
| 34 | "type" integer DEFAULT 1 NOT NULL,
|
---|
| 35 | val character varying(100) DEFAULT ''::character varying NOT NULL,
|
---|
| 36 | distance integer DEFAULT 0 NOT NULL,
|
---|
| 37 | weight integer DEFAULT 0 NOT NULL,
|
---|
| 38 | port integer DEFAULT 0 NOT NULL,
|
---|
| 39 | ttl integer DEFAULT 86400 NOT NULL,
|
---|
| 40 | description character varying(255)
|
---|
| 41 | );
|
---|
| 42 |
|
---|
| 43 | -- default records for the default group
|
---|
| 44 | COPY default_records (record_id, group_id, host, "type", val, distance, weight, port, ttl, description) FROM stdin;
|
---|
| 45 | 1 1 ns1.example.com:hostmaster.DOMAIN 6 10800:3600:604800:5400 0 0 0 86400 \N
|
---|
| 46 | 2 1 DOMAIN 2 ns2.example.com 0 0 0 7200 \N
|
---|
| 47 | 3 1 DOMAIN 2 ns1.example.com 0 0 0 7200 \N
|
---|
| 48 | 4 1 DOMAIN 1 10.0.0.4 0 0 0 7200 \N
|
---|
| 49 | 5 1 DOMAIN 15 mx1.example.com 10 0 0 7200 \N
|
---|
| 50 | 6 1 www.DOMAIN 5 DOMAIN 0 0 0 10800 \N
|
---|
| 51 | 7 1 DOMAIN 16 "v=spf1 a mx -all" 0 0 0 10800 \N
|
---|
| 52 | \.
|
---|
| 53 |
|
---|
| 54 | CREATE TABLE records (
|
---|
| 55 | domain_id integer NOT NULL,
|
---|
| 56 | record_id serial NOT NULL,
|
---|
| 57 | host character varying(100) DEFAULT ''::character varying NOT NULL,
|
---|
| 58 | "type" integer DEFAULT 1 NOT NULL,
|
---|
| 59 | val character varying(100) DEFAULT ''::character varying NOT NULL,
|
---|
| 60 | distance integer DEFAULT 0 NOT NULL,
|
---|
| 61 | weight integer DEFAULT 0 NOT NULL,
|
---|
| 62 | port integer DEFAULT 0 NOT NULL,
|
---|
| 63 | ttl integer DEFAULT 86400 NOT NULL,
|
---|
| 64 | description character varying(255)
|
---|
| 65 | );
|
---|
| 66 |
|
---|
| 67 | CREATE TABLE rectypes (
|
---|
| 68 | val integer NOT NULL,
|
---|
| 69 | name character varying(12) NOT NULL,
|
---|
| 70 | stdflag integer DEFAULT 1 NOT NULL,
|
---|
| 71 | listorder integer DEFAULT 255 NOT NULL
|
---|
| 72 | );
|
---|
| 73 |
|
---|
| 74 | -- Types are required. NB: these are vaguely read-only too
|
---|
| 75 | COPY rectypes (val, name, stdflag, listorder) FROM stdin;
|
---|
| 76 | 1 A 1 1
|
---|
| 77 | 2 NS 1 2
|
---|
| 78 | 3 MD 2 255
|
---|
| 79 | 4 MF 2 255
|
---|
| 80 | 5 CNAME 1 6
|
---|
| 81 | 6 SOA 0 8
|
---|
| 82 | 7 MB 3 255
|
---|
| 83 | 8 MG 3 255
|
---|
| 84 | 9 MR 3 255
|
---|
| 85 | 10 NULL 3 255
|
---|
| 86 | 11 WKS 3 255
|
---|
| 87 | 12 PTR 2 4
|
---|
| 88 | 13 HINFO 3 255
|
---|
| 89 | 14 MINFO 3 255
|
---|
| 90 | 15 MX 1 3
|
---|
| 91 | 16 TXT 1 5
|
---|
| 92 | 17 RP 2 255
|
---|
| 93 | 18 AFSDB 3 255
|
---|
| 94 | 19 X25 3 255
|
---|
| 95 | 20 ISDN 3 255
|
---|
| 96 | 21 RT 3 255
|
---|
| 97 | 22 NSAP 3 255
|
---|
| 98 | 23 NSAP-PTR 3 255
|
---|
| 99 | 24 SIG 3 255
|
---|
| 100 | 25 KEY 3 255
|
---|
| 101 | 26 PX 3 255
|
---|
| 102 | 27 GPOS 3 255
|
---|
| 103 | 28 AAAA 2 2
|
---|
| 104 | 29 LOC 3 255
|
---|
| 105 | 30 NXT 3 255
|
---|
| 106 | 31 EID 3 255
|
---|
| 107 | 32 NIMLOC 3 255
|
---|
| 108 | 33 SRV 1 7
|
---|
| 109 | 34 ATMA 3 255
|
---|
| 110 | 35 NAPTR 3 255
|
---|
| 111 | 36 KX 3 255
|
---|
| 112 | 37 CERT 3 255
|
---|
| 113 | 38 A6 3 3
|
---|
| 114 | 39 DNAME 3 255
|
---|
| 115 | 40 SINK 3 255
|
---|
| 116 | 41 OPT 3 255
|
---|
| 117 | 42 APL 3 255
|
---|
| 118 | 43 DS 3 255
|
---|
| 119 | 44 SSHFP 3 255
|
---|
| 120 | 45 IPSECKEY 3 255
|
---|
| 121 | 46 RRSIG 3 255
|
---|
| 122 | 47 NSEC 3 255
|
---|
| 123 | 48 DNSKEY 3 255
|
---|
| 124 | 49 DHCID 3 255
|
---|
| 125 | 50 NSEC3 3 255
|
---|
| 126 | 51 NSEC3PARAM 3 255
|
---|
| 127 | 55 HIP 3 255
|
---|
| 128 | 99 SPF 3 255
|
---|
| 129 | 100 UINFO 3 255
|
---|
| 130 | 101 UID 3 255
|
---|
| 131 | 102 GID 3 255
|
---|
| 132 | 103 UNSPEC 3 255
|
---|
| 133 | 249 TKEY 3 255
|
---|
| 134 | 250 TSIG 3 255
|
---|
| 135 | 251 IXFR 3 255
|
---|
| 136 | 252 AXFR 3 255
|
---|
| 137 | 253 MAILB 3 255
|
---|
| 138 | 254 MAILA 3 255
|
---|
| 139 | 32768 TA 3 255
|
---|
| 140 | 32769 DLV 3 255
|
---|
| 141 | \.
|
---|
| 142 |
|
---|
| 143 | CREATE TABLE users (
|
---|
| 144 | user_id serial NOT NULL,
|
---|
| 145 | group_id integer DEFAULT 1 NOT NULL,
|
---|
| 146 | username character varying(60) NOT NULL,
|
---|
| 147 | "password" character varying(34) NOT NULL,
|
---|
| 148 | firstname character varying(30),
|
---|
| 149 | lastname character varying(30),
|
---|
| 150 | phone character varying(15),
|
---|
| 151 | "type" character(1) DEFAULT 'S'::bpchar NOT NULL,
|
---|
| 152 | status integer DEFAULT 1 NOT NULL,
|
---|
| 153 | acl character varying(40) DEFAULT 'b'::character varying NOT NULL
|
---|
| 154 | );
|
---|
| 155 |
|
---|
| 156 | -- create initial default user? may be better to create an "initialize" script or something
|
---|
| 157 | COPY users (user_id, group_id, username, "password", firstname, lastname, phone, "type", status, acl) FROM stdin;
|
---|
| 158 | 1 1 test@test $1$BByge8u2$48AaGX3YeHplfErX5Tlqa1 \N \N \N S 1 A
|
---|
| 159 | \.
|
---|
| 160 |
|
---|
| 161 | CREATE TABLE log (
|
---|
| 162 | domain_id integer,
|
---|
| 163 | user_id integer,
|
---|
| 164 | group_id integer,
|
---|
| 165 | email character varying(60),
|
---|
| 166 | name character varying(60),
|
---|
| 167 | entry character varying(200),
|
---|
| 168 | stamp timestamp with time zone
|
---|
| 169 | );
|
---|
| 170 |
|
---|
| 171 | --
|
---|
| 172 | -- contraints. add these here so initial data doesn't get added strangely.
|
---|
| 173 | --
|
---|
| 174 |
|
---|
| 175 | -- primary keys
|
---|
| 176 | ALTER TABLE ONLY groups
|
---|
| 177 | ADD CONSTRAINT groups_group_id_key UNIQUE (group_id);
|
---|
| 178 |
|
---|
| 179 | ALTER TABLE ONLY domains
|
---|
| 180 | ADD CONSTRAINT domains_pkey PRIMARY KEY ("domain");
|
---|
| 181 |
|
---|
| 182 | ALTER TABLE ONLY domains
|
---|
| 183 | ADD CONSTRAINT domains_domain_id_key UNIQUE (domain_id);
|
---|
| 184 |
|
---|
| 185 | ALTER TABLE ONLY default_records
|
---|
| 186 | ADD CONSTRAINT default_records_pkey PRIMARY KEY (record_id);
|
---|
| 187 |
|
---|
| 188 | ALTER TABLE ONLY records
|
---|
| 189 | ADD CONSTRAINT records_pkey PRIMARY KEY (record_id);
|
---|
| 190 |
|
---|
| 191 | ALTER TABLE ONLY rectypes
|
---|
| 192 | ADD CONSTRAINT rectypes_pkey PRIMARY KEY (val, name);
|
---|
| 193 |
|
---|
| 194 | ALTER TABLE ONLY users
|
---|
| 195 | ADD CONSTRAINT users_pkey PRIMARY KEY (username);
|
---|
| 196 |
|
---|
| 197 | ALTER TABLE ONLY users
|
---|
| 198 | ADD CONSTRAINT uidu UNIQUE (user_id);
|
---|
| 199 |
|
---|
| 200 | -- foreign keys
|
---|
| 201 | ALTER TABLE ONLY domains
|
---|
| 202 | ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
|
---|
| 203 |
|
---|
| 204 | ALTER TABLE ONLY default_records
|
---|
| 205 | ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
|
---|
| 206 |
|
---|
| 207 | ALTER TABLE ONLY records
|
---|
| 208 | ADD CONSTRAINT "$1" FOREIGN KEY (domain_id) REFERENCES domains(domain_id);
|
---|
| 209 |
|
---|
| 210 | ALTER TABLE ONLY users
|
---|
| 211 | ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
|
---|
| 212 |
|
---|
| 213 | ALTER TABLE ONLY groups
|
---|
| 214 | ADD CONSTRAINT group_parent FOREIGN KEY (parent_group_id) REFERENCES groups(group_id);
|
---|
| 215 |
|
---|
| 216 | -- set sequence start values - make sure we don't screw up adding
|
---|
| 217 | -- records to tables that already have a few entries
|
---|
| 218 |
|
---|
| 219 | SELECT pg_catalog.setval('groups_group_id_seq', 52, true);
|
---|
| 220 |
|
---|
| 221 | SELECT pg_catalog.setval('domains_domain_id_seq', 953, true);
|
---|
| 222 |
|
---|
| 223 | SELECT pg_catalog.setval('default_records_record_id_seq', 320, true);
|
---|
| 224 |
|
---|
| 225 | SELECT pg_catalog.setval('records_record_id_seq', 660, true);
|
---|
| 226 |
|
---|
| 227 | SELECT pg_catalog.setval('users_user_id_seq', 37, true);
|
---|