source: trunk/dns.sql@ 154

Last change on this file since 154 was 130, checked in by Kris Deugau, 13 years ago

/trunk

Duhhhhh... "text" fields don't have any performance penalty
over varchar or char. Rip out the longrecs business in favour
of much simpler record tables. Reverts addition of same from
r90.

File size: 7.9 KB
RevLine 
[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
8CREATE TABLE default_records (
9 record_id serial NOT NULL,
10 group_id integer DEFAULT 1 NOT NULL,
[130]11 host text DEFAULT '' NOT NULL,
[50]12 "type" integer DEFAULT 1 NOT NULL,
[130]13 val text DEFAULT '' NOT NULL,
[50]14 distance integer DEFAULT 0 NOT NULL,
15 weight integer DEFAULT 0 NOT NULL,
16 port integer DEFAULT 0 NOT NULL,
17 ttl integer DEFAULT 86400 NOT NULL,
[130]18 description text
[50]19);
20
21-- default records for the default group
22COPY default_records (record_id, group_id, host, "type", val, distance, weight, port, ttl, description) FROM stdin;
231 1 ns1.example.com:hostmaster.DOMAIN 6 10800:3600:604800:5400 0 0 0 86400 \N
242 1 DOMAIN 2 ns2.example.com 0 0 0 7200 \N
253 1 DOMAIN 2 ns1.example.com 0 0 0 7200 \N
264 1 DOMAIN 1 10.0.0.4 0 0 0 7200 \N
275 1 DOMAIN 15 mx1.example.com 10 0 0 7200 \N
286 1 www.DOMAIN 5 DOMAIN 0 0 0 10800 \N
297 1 DOMAIN 16 "v=spf1 a mx -all" 0 0 0 10800 \N
30\.
31
[85]32CREATE TABLE domains (
33 domain_id serial NOT NULL,
34 "domain" character varying(80) NOT NULL,
35 group_id integer DEFAULT 1 NOT NULL,
36 description character varying(255) DEFAULT ''::character varying NOT NULL,
37 status integer DEFAULT 1 NOT NULL,
38 zserial integer,
39 sertype character(1) DEFAULT 'D'::bpchar
40);
41
42CREATE TABLE groups (
43 group_id serial NOT NULL,
44 parent_group_id integer DEFAULT 1 NOT NULL,
45 group_name character varying(255) DEFAULT ''::character varying NOT NULL,
46 permission_id integer DEFAULT 1 NOT NULL,
47 inherit_perm boolean DEFAULT true NOT NULL
48);
49
50-- Provide a basic default group
[86]51COPY groups (group_id, parent_group_id, permission_id, group_name) FROM stdin;
[85]521 1 1 default
53\.
54
[91]55-- entry is text due to possible long entries from AXFR - a domain with "many"
56-- odd records will overflow varchar(200)
[85]57CREATE TABLE log (
[89]58 log_id serial NOT NULL,
[85]59 domain_id integer,
60 user_id integer,
61 group_id integer,
62 email character varying(60),
63 name character varying(60),
[91]64 entry text,
[85]65 stamp timestamp with time zone DEFAULT now()
66);
67
68CREATE TABLE permissions (
69 permission_id serial NOT NULL,
70 "admin" boolean DEFAULT false NOT NULL,
71 self_edit boolean DEFAULT false NOT NULL,
72 group_create boolean DEFAULT false NOT NULL,
73 group_edit boolean DEFAULT false NOT NULL,
74 group_delete boolean DEFAULT false NOT NULL,
75 user_create boolean DEFAULT false NOT NULL,
76 user_edit boolean DEFAULT false NOT NULL,
77 user_delete boolean DEFAULT false NOT NULL,
78 domain_create boolean DEFAULT false NOT NULL,
79 domain_edit boolean DEFAULT false NOT NULL,
80 domain_delete boolean DEFAULT false NOT NULL,
81 record_create boolean DEFAULT false NOT NULL,
82 record_edit boolean DEFAULT false NOT NULL,
83 record_delete boolean DEFAULT false NOT NULL,
[86]84 user_id integer UNIQUE,
85 group_id integer UNIQUE
[85]86);
87
88-- Need *two* basic permissions; one for the initial group, one for the default admin user
[86]89COPY permissions (permission_id, admin, self_edit, group_create, group_edit, group_delete, user_create, user_edit, user_delete, domain_create, domain_edit, domain_delete, record_create, record_edit, record_delete, user_id, group_id) FROM stdin;
[89]901 f f f f f f f f t t t t t t \N 1
[86]912 t f f f f f f f f f f f f f 1 \N
[85]92\.
93
[89]94-- fixme: need to handle looooong records (eg, SPF)
[50]95CREATE TABLE records (
96 domain_id integer NOT NULL,
97 record_id serial NOT NULL,
[130]98 host text DEFAULT '' NOT NULL,
[50]99 "type" integer DEFAULT 1 NOT NULL,
[130]100 val text DEFAULT '' NOT NULL,
[50]101 distance integer DEFAULT 0 NOT NULL,
102 weight integer DEFAULT 0 NOT NULL,
103 port integer DEFAULT 0 NOT NULL,
[85]104 ttl integer DEFAULT 7200 NOT NULL,
[130]105 description text
[50]106);
107
108CREATE TABLE rectypes (
109 val integer NOT NULL,
110 name character varying(12) NOT NULL,
111 stdflag integer DEFAULT 1 NOT NULL,
[102]112 listorder integer DEFAULT 255 NOT NULL,
113 alphaorder integer DEFAULT 32768 NOT NULL
[50]114);
115
116-- Types are required. NB: these are vaguely read-only too
[85]117-- data from http://www.iana.org/assignments/dns-parameters
[102]118COPY rectypes (val, name, stdflag, listorder, alphaorder) FROM stdin;
1191 A 1 1 1
1202 NS 1 2 37
1213 MD 2 255 29
1224 MF 2 255 30
1235 CNAME 1 6 9
1246 SOA 0 8 53
1257 MB 3 255 28
1268 MG 3 255 31
1279 MR 3 255 33
12810 NULL 3 255 43
12911 WKS 3 255 64
13012 PTR 2 4 46
13113 HINFO 3 255 18
13214 MINFO 3 255 32
13315 MX 1 3 34
13416 TXT 1 5 60
13517 RP 2 255 48
13618 AFSDB 3 255 4
13719 X25 3 255 65
13820 ISDN 3 255 21
13921 RT 3 255 50
14022 NSAP 3 255 38
14123 NSAP-PTR 3 255 39
14224 SIG 3 255 51
14325 KEY 3 255 23
14426 PX 3 255 47
14527 GPOS 3 255 17
14628 AAAA 2 2 3
14729 LOC 3 255 25
14830 NXT 3 255 44
14931 EID 3 255 15
15032 NIMLOC 3 255 36
15133 SRV 1 7 55
15234 ATMA 3 255 6
15335 NAPTR 3 255 35
15436 KX 3 255 24
15537 CERT 3 255 8
15638 A6 3 3 2
15739 DNAME 3 255 12
15840 SINK 3 255 52
15941 OPT 3 255 45
16042 APL 3 255 5
16143 DS 3 255 14
16244 SSHFP 3 255 56
16345 IPSECKEY 3 255 20
16446 RRSIG 3 255 49
16547 NSEC 3 255 40
16648 DNSKEY 3 255 13
16749 DHCID 3 255 10
16850 NSEC3 3 255 41
16951 NSEC3PARAM 3 255 42
17055 HIP 3 255 19
17199 SPF 3 255 54
172100 UINFO 3 255 62
173101 UID 3 255 61
174102 GID 3 255 16
175103 UNSPEC 3 255 63
176249 TKEY 3 255 58
177250 TSIG 3 255 59
178251 IXFR 3 255 22
179252 AXFR 3 255 7
180253 MAILB 3 255 27
181254 MAILA 3 255 26
18232768 TA 3 255 57
18332769 DLV 3 255 11
[50]184\.
185
186CREATE TABLE users (
187 user_id serial NOT NULL,
188 group_id integer DEFAULT 1 NOT NULL,
189 username character varying(60) NOT NULL,
190 "password" character varying(34) NOT NULL,
[85]191 firstname character varying(60),
192 lastname character varying(60),
[50]193 phone character varying(15),
194 "type" character(1) DEFAULT 'S'::bpchar NOT NULL,
195 status integer DEFAULT 1 NOT NULL,
[85]196 permission_id integer DEFAULT 1 NOT NULL,
197 inherit_perm boolean DEFAULT true NOT NULL
[50]198);
199
200-- create initial default user? may be better to create an "initialize" script or something
[86]201COPY users (user_id, group_id, username, "password", firstname, lastname, phone, "type", status, permission_id, inherit_perm) FROM stdin;
[89]2021 1 admin $1$PfEBUv9d$wV2/UG4gmKk08DLmdE8/d. Initial User \N S 1 2 f
[50]203\.
204
205--
206-- contraints. add these here so initial data doesn't get added strangely.
207--
208
209-- primary keys
[65]210ALTER TABLE ONLY permissions
211 ADD CONSTRAINT permissions_permission_id_key UNIQUE (permission_id);
212
[50]213ALTER TABLE ONLY groups
214 ADD CONSTRAINT groups_group_id_key UNIQUE (group_id);
215
216ALTER TABLE ONLY domains
217 ADD CONSTRAINT domains_pkey PRIMARY KEY ("domain");
218
219ALTER TABLE ONLY domains
220 ADD CONSTRAINT domains_domain_id_key UNIQUE (domain_id);
221
222ALTER TABLE ONLY default_records
223 ADD CONSTRAINT default_records_pkey PRIMARY KEY (record_id);
224
225ALTER TABLE ONLY records
226 ADD CONSTRAINT records_pkey PRIMARY KEY (record_id);
227
228ALTER TABLE ONLY rectypes
229 ADD CONSTRAINT rectypes_pkey PRIMARY KEY (val, name);
230
231ALTER TABLE ONLY users
232 ADD CONSTRAINT users_pkey PRIMARY KEY (username);
233
234ALTER TABLE ONLY users
235 ADD CONSTRAINT uidu UNIQUE (user_id);
236
237-- foreign keys
[65]238-- fixme: permissions FK refs
[50]239ALTER TABLE ONLY domains
240 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
241
242ALTER TABLE ONLY default_records
243 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
244
245ALTER TABLE ONLY records
246 ADD CONSTRAINT "$1" FOREIGN KEY (domain_id) REFERENCES domains(domain_id);
247
248ALTER TABLE ONLY users
249 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
250
251ALTER TABLE ONLY groups
252 ADD CONSTRAINT group_parent FOREIGN KEY (parent_group_id) REFERENCES groups(group_id);
[86]253
254-- set starting sequence numbers, since we've inserted data before they're active
255SELECT pg_catalog.setval('default_records_record_id_seq', 8, true);
256SELECT pg_catalog.setval('domains_domain_id_seq', 1, false);
[87]257SELECT pg_catalog.setval('groups_group_id_seq', 1, true);
258SELECT pg_catalog.setval('permissions_permission_id_seq', 2, true);
[86]259SELECT pg_catalog.setval('records_record_id_seq', 1, false);
260SELECT pg_catalog.setval('users_user_id_seq', 2, false);
Note: See TracBrowser for help on using the repository browser.