source: trunk/dns.sql@ 85

Last change on this file since 85 was 85, checked in by Kris Deugau, 14 years ago

/trunk

Update SQL tabledef file

File size: 7.3 KB
Line 
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,
11 host character varying(100) DEFAULT ''::character varying NOT NULL,
12 "type" integer DEFAULT 1 NOT NULL,
13 val character varying(100) DEFAULT ''::character varying NOT NULL,
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,
18 description character varying(255)
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
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
51COPY groups (group_id, parent_group_id, group_name) FROM stdin;
521 1 1 default
53\.
54
55CREATE TABLE log (
56 domain_id integer,
57 user_id integer,
58 group_id integer,
59 email character varying(60),
60 name character varying(60),
61 entry character varying(200),
62 stamp timestamp with time zone DEFAULT now()
63);
64
65CREATE TABLE permissions (
66 permission_id serial NOT NULL,
67 "admin" boolean DEFAULT false NOT NULL,
68 self_edit boolean DEFAULT false NOT NULL,
69 group_create boolean DEFAULT false NOT NULL,
70 group_edit boolean DEFAULT false NOT NULL,
71 group_delete boolean DEFAULT false NOT NULL,
72 user_create boolean DEFAULT false NOT NULL,
73 user_edit boolean DEFAULT false NOT NULL,
74 user_delete boolean DEFAULT false NOT NULL,
75 domain_create boolean DEFAULT false NOT NULL,
76 domain_edit boolean DEFAULT false NOT NULL,
77 domain_delete boolean DEFAULT false NOT NULL,
78 record_create boolean DEFAULT false NOT NULL,
79 record_edit boolean DEFAULT false NOT NULL,
80 record_delete boolean DEFAULT false NOT NULL,
81 user_id integer DEFAULT 0 NOT NULL,
82 group_id integer DEFAULT 0 NOT NULL
83);
84
85-- Need *two* basic permissions; one for the initial group, one for the default admin user
86COPY 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) FROM stdin;
871 n n n n n n n n n n n n n n
882 y n n n n n n n n n n n n n
89\.
90
91-- fixeme: need to handle looooong TXT records (eg, SPF)
92CREATE TABLE records (
93 domain_id integer NOT NULL,
94 record_id serial NOT NULL,
95 host character varying(100) DEFAULT ''::character varying NOT NULL,
96 "type" integer DEFAULT 1 NOT NULL,
97 val character varying(100) DEFAULT ''::character varying NOT NULL,
98 distance integer DEFAULT 0 NOT NULL,
99 weight integer DEFAULT 0 NOT NULL,
100 port integer DEFAULT 0 NOT NULL,
101 ttl integer DEFAULT 7200 NOT NULL,
102 description character varying(255)
103);
104
105CREATE TABLE rectypes (
106 val integer NOT NULL,
107 name character varying(12) NOT NULL,
108 stdflag integer DEFAULT 1 NOT NULL,
109 listorder integer DEFAULT 255 NOT NULL
110);
111
112-- Types are required. NB: these are vaguely read-only too
113-- data from http://www.iana.org/assignments/dns-parameters
114COPY rectypes (val, name, stdflag, listorder) FROM stdin;
1151 A 1 1
1162 NS 1 2
1173 MD 2 255
1184 MF 2 255
1195 CNAME 1 6
1206 SOA 0 8
1217 MB 3 255
1228 MG 3 255
1239 MR 3 255
12410 NULL 3 255
12511 WKS 3 255
12612 PTR 2 4
12713 HINFO 3 255
12814 MINFO 3 255
12915 MX 1 3
13016 TXT 1 5
13117 RP 2 255
13218 AFSDB 3 255
13319 X25 3 255
13420 ISDN 3 255
13521 RT 3 255
13622 NSAP 3 255
13723 NSAP-PTR 3 255
13824 SIG 3 255
13925 KEY 3 255
14026 PX 3 255
14127 GPOS 3 255
14228 AAAA 2 2
14329 LOC 3 255
14430 NXT 3 255
14531 EID 3 255
14632 NIMLOC 3 255
14733 SRV 1 7
14834 ATMA 3 255
14935 NAPTR 3 255
15036 KX 3 255
15137 CERT 3 255
15238 A6 3 3
15339 DNAME 3 255
15440 SINK 3 255
15541 OPT 3 255
15642 APL 3 255
15743 DS 3 255
15844 SSHFP 3 255
15945 IPSECKEY 3 255
16046 RRSIG 3 255
16147 NSEC 3 255
16248 DNSKEY 3 255
16349 DHCID 3 255
16450 NSEC3 3 255
16551 NSEC3PARAM 3 255
16655 HIP 3 255
16799 SPF 3 255
168100 UINFO 3 255
169101 UID 3 255
170102 GID 3 255
171103 UNSPEC 3 255
172249 TKEY 3 255
173250 TSIG 3 255
174251 IXFR 3 255
175252 AXFR 3 255
176253 MAILB 3 255
177254 MAILA 3 255
17832768 TA 3 255
17932769 DLV 3 255
180\.
181
182CREATE TABLE users (
183 user_id serial NOT NULL,
184 group_id integer DEFAULT 1 NOT NULL,
185 username character varying(60) NOT NULL,
186 "password" character varying(34) NOT NULL,
187 firstname character varying(60),
188 lastname character varying(60),
189 phone character varying(15),
190 "type" character(1) DEFAULT 'S'::bpchar NOT NULL,
191 status integer DEFAULT 1 NOT NULL,
192 permission_id integer DEFAULT 1 NOT NULL,
193 inherit_perm boolean DEFAULT true NOT NULL
194);
195
196-- create initial default user? may be better to create an "initialize" script or something
197COPY users (user_id, group_id, username, "password", firstname, lastname, phone, "type", status, acl) FROM stdin;
1981 1 test@test $1$BByge8u2$48AaGX3YeHplfErX5Tlqa1 \N \N \N S 1 A 2
199\.
200
201--
202-- contraints. add these here so initial data doesn't get added strangely.
203--
204
205-- primary keys
206ALTER TABLE ONLY permissions
207 ADD CONSTRAINT permissions_permission_id_key UNIQUE (permission_id);
208
209ALTER TABLE ONLY groups
210 ADD CONSTRAINT groups_group_id_key UNIQUE (group_id);
211
212ALTER TABLE ONLY domains
213 ADD CONSTRAINT domains_pkey PRIMARY KEY ("domain");
214
215ALTER TABLE ONLY domains
216 ADD CONSTRAINT domains_domain_id_key UNIQUE (domain_id);
217
218ALTER TABLE ONLY default_records
219 ADD CONSTRAINT default_records_pkey PRIMARY KEY (record_id);
220
221ALTER TABLE ONLY records
222 ADD CONSTRAINT records_pkey PRIMARY KEY (record_id);
223
224ALTER TABLE ONLY rectypes
225 ADD CONSTRAINT rectypes_pkey PRIMARY KEY (val, name);
226
227ALTER TABLE ONLY users
228 ADD CONSTRAINT users_pkey PRIMARY KEY (username);
229
230ALTER TABLE ONLY users
231 ADD CONSTRAINT uidu UNIQUE (user_id);
232
233-- foreign keys
234-- fixme: permissions FK refs
235ALTER TABLE ONLY domains
236 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
237
238ALTER TABLE ONLY default_records
239 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
240
241ALTER TABLE ONLY records
242 ADD CONSTRAINT "$1" FOREIGN KEY (domain_id) REFERENCES domains(domain_id);
243
244ALTER TABLE ONLY users
245 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
246
247ALTER TABLE ONLY groups
248 ADD CONSTRAINT group_parent FOREIGN KEY (parent_group_id) REFERENCES groups(group_id);
Note: See TracBrowser for help on using the repository browser.