source: trunk/dns.sql@ 67

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

/trunk

checkpoint, adding permissions/ACL support

File size: 7.6 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
8-- tabledefs and preloaded data bits
9CREATE TABLE permissions (
10 permission_id SERIAL NOT NULL,
11 admin boolean DEFAULT 'n' NOT NULL,
12 self_edit boolean DEFAULT 'n' NOT NULL,
13 group_create boolean DEFAULT 'n' NOT NULL,
14 group_edit boolean DEFAULT 'n' NOT NULL,
15 group_delete boolean DEFAULT 'n' NOT NULL,
16 user_create boolean DEFAULT 'n' NOT NULL,
17 user_edit boolean DEFAULT 'n' NOT NULL,
18 user_delete boolean DEFAULT 'n' NOT NULL,
19 domain_create boolean DEFAULT 'n' NOT NULL,
20 domain_edit boolean DEFAULT 'n' NOT NULL,
21 domain_delete boolean DEFAULT 'n' NOT NULL,
22 record_create boolean DEFAULT 'n' NOT NULL,
23 record_edit boolean DEFAULT 'n' NOT NULL,
24 record_delete boolean DEFAULT 'n' NOT NULL
25);
26
27-- Need *two* basic permissions; one for the initial group, one for the default admin user
28COPY 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;
291 n n n n n n n n n n n n n n
302 y n n n n n n n n n n n n n
31\.
32
33CREATE TABLE groups (
34 group_id serial NOT NULL,
35 parent_group_id integer DEFAULT 1 NOT NULL,
36 permission_id integer DEFAULT 1 NOT NULL,
37 group_name character varying(255) DEFAULT ''::character varying NOT NULL
38);
39
40-- Provide a basic default group
41COPY groups (group_id, parent_group_id, group_name) FROM stdin;
421 1 1 default
43\.
44
45CREATE TABLE domains (
46 domain_id serial NOT NULL,
47 "domain" character varying(80) NOT NULL,
48 group_id integer DEFAULT 1 NOT NULL,
49 description character varying(255) DEFAULT ''::character varying NOT NULL,
50 status integer DEFAULT 1 NOT NULL,
51 zserial integer,
52 sertype character(1) DEFAULT 'D'::bpchar
53);
54
55CREATE TABLE default_records (
56 record_id serial NOT NULL,
57 group_id integer DEFAULT 1 NOT NULL,
58 host character varying(100) DEFAULT ''::character varying NOT NULL,
59 "type" integer DEFAULT 1 NOT NULL,
60 val character varying(100) DEFAULT ''::character varying NOT NULL,
61 distance integer DEFAULT 0 NOT NULL,
62 weight integer DEFAULT 0 NOT NULL,
63 port integer DEFAULT 0 NOT NULL,
64 ttl integer DEFAULT 86400 NOT NULL,
65 description character varying(255)
66);
67
68-- default records for the default group
69COPY default_records (record_id, group_id, host, "type", val, distance, weight, port, ttl, description) FROM stdin;
701 1 ns1.example.com:hostmaster.DOMAIN 6 10800:3600:604800:5400 0 0 0 86400 \N
712 1 DOMAIN 2 ns2.example.com 0 0 0 7200 \N
723 1 DOMAIN 2 ns1.example.com 0 0 0 7200 \N
734 1 DOMAIN 1 10.0.0.4 0 0 0 7200 \N
745 1 DOMAIN 15 mx1.example.com 10 0 0 7200 \N
756 1 www.DOMAIN 5 DOMAIN 0 0 0 10800 \N
767 1 DOMAIN 16 "v=spf1 a mx -all" 0 0 0 10800 \N
77\.
78
79CREATE TABLE records (
80 domain_id integer NOT NULL,
81 record_id serial NOT NULL,
82 host character varying(100) DEFAULT ''::character varying NOT NULL,
83 "type" integer DEFAULT 1 NOT NULL,
84 val character varying(100) DEFAULT ''::character varying NOT NULL,
85 distance integer DEFAULT 0 NOT NULL,
86 weight integer DEFAULT 0 NOT NULL,
87 port integer DEFAULT 0 NOT NULL,
88 ttl integer DEFAULT 86400 NOT NULL,
89 description character varying(255)
90);
91
92CREATE TABLE rectypes (
93 val integer NOT NULL,
94 name character varying(12) NOT NULL,
95 stdflag integer DEFAULT 1 NOT NULL,
96 listorder integer DEFAULT 255 NOT NULL
97);
98
99-- Types are required. NB: these are vaguely read-only too
100COPY rectypes (val, name, stdflag, listorder) FROM stdin;
1011 A 1 1
1022 NS 1 2
1033 MD 2 255
1044 MF 2 255
1055 CNAME 1 6
1066 SOA 0 8
1077 MB 3 255
1088 MG 3 255
1099 MR 3 255
11010 NULL 3 255
11111 WKS 3 255
11212 PTR 2 4
11313 HINFO 3 255
11414 MINFO 3 255
11515 MX 1 3
11616 TXT 1 5
11717 RP 2 255
11818 AFSDB 3 255
11919 X25 3 255
12020 ISDN 3 255
12121 RT 3 255
12222 NSAP 3 255
12323 NSAP-PTR 3 255
12424 SIG 3 255
12525 KEY 3 255
12626 PX 3 255
12727 GPOS 3 255
12828 AAAA 2 2
12929 LOC 3 255
13030 NXT 3 255
13131 EID 3 255
13232 NIMLOC 3 255
13333 SRV 1 7
13434 ATMA 3 255
13535 NAPTR 3 255
13636 KX 3 255
13737 CERT 3 255
13838 A6 3 3
13939 DNAME 3 255
14040 SINK 3 255
14141 OPT 3 255
14242 APL 3 255
14343 DS 3 255
14444 SSHFP 3 255
14545 IPSECKEY 3 255
14646 RRSIG 3 255
14747 NSEC 3 255
14848 DNSKEY 3 255
14949 DHCID 3 255
15050 NSEC3 3 255
15151 NSEC3PARAM 3 255
15255 HIP 3 255
15399 SPF 3 255
154100 UINFO 3 255
155101 UID 3 255
156102 GID 3 255
157103 UNSPEC 3 255
158249 TKEY 3 255
159250 TSIG 3 255
160251 IXFR 3 255
161252 AXFR 3 255
162253 MAILB 3 255
163254 MAILA 3 255
16432768 TA 3 255
16532769 DLV 3 255
166\.
167
168CREATE TABLE users (
169 user_id serial NOT NULL,
170 group_id integer DEFAULT 1 NOT NULL,
171 username character varying(60) NOT NULL,
172 "password" character varying(34) NOT NULL,
173 firstname character varying(30),
174 lastname character varying(30),
175 phone character varying(15),
176 "type" character(1) DEFAULT 'S'::bpchar NOT NULL,
177 status integer DEFAULT 1 NOT NULL,
178 acl character varying(40) DEFAULT 'b'::character varying NOT NULL,
179 permission_id DEFAULT 1 NOT NULL,
180);
181
182-- create initial default user? may be better to create an "initialize" script or something
183COPY users (user_id, group_id, username, "password", firstname, lastname, phone, "type", status, acl) FROM stdin;
1841 1 test@test $1$BByge8u2$48AaGX3YeHplfErX5Tlqa1 \N \N \N S 1 A 2
185\.
186
187CREATE TABLE log (
188 domain_id integer,
189 user_id integer,
190 group_id integer,
191 email character varying(60),
192 name character varying(60),
193 entry character varying(200),
194 stamp timestamp with time zone
195);
196
197--
198-- contraints. add these here so initial data doesn't get added strangely.
199--
200
201-- primary keys
202ALTER TABLE ONLY permissions
203 ADD CONSTRAINT permissions_permission_id_key UNIQUE (permission_id);
204
205ALTER TABLE ONLY groups
206 ADD CONSTRAINT groups_group_id_key UNIQUE (group_id);
207
208ALTER TABLE ONLY domains
209 ADD CONSTRAINT domains_pkey PRIMARY KEY ("domain");
210
211ALTER TABLE ONLY domains
212 ADD CONSTRAINT domains_domain_id_key UNIQUE (domain_id);
213
214ALTER TABLE ONLY default_records
215 ADD CONSTRAINT default_records_pkey PRIMARY KEY (record_id);
216
217ALTER TABLE ONLY records
218 ADD CONSTRAINT records_pkey PRIMARY KEY (record_id);
219
220ALTER TABLE ONLY rectypes
221 ADD CONSTRAINT rectypes_pkey PRIMARY KEY (val, name);
222
223ALTER TABLE ONLY users
224 ADD CONSTRAINT users_pkey PRIMARY KEY (username);
225
226ALTER TABLE ONLY users
227 ADD CONSTRAINT uidu UNIQUE (user_id);
228
229-- foreign keys
230-- fixme: permissions FK refs
231ALTER TABLE ONLY domains
232 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
233
234ALTER TABLE ONLY default_records
235 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
236
237ALTER TABLE ONLY records
238 ADD CONSTRAINT "$1" FOREIGN KEY (domain_id) REFERENCES domains(domain_id);
239
240ALTER TABLE ONLY users
241 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
242
243ALTER TABLE ONLY groups
244 ADD CONSTRAINT group_parent FOREIGN KEY (parent_group_id) REFERENCES groups(group_id);
245
246-- set sequence start values - make sure we don't screw up adding
247-- records to tables that already have a few entries
248SELECT pg_catalog.setval('permissions_permission_id_seq', 2, true);
249
250SELECT pg_catalog.setval('groups_group_id_seq', 52, true);
251
252SELECT pg_catalog.setval('domains_domain_id_seq', 953, true);
253
254SELECT pg_catalog.setval('default_records_record_id_seq', 320, true);
255
256SELECT pg_catalog.setval('records_record_id_seq', 660, true);
257
258SELECT pg_catalog.setval('users_user_id_seq', 37, true);
Note: See TracBrowser for help on using the repository browser.