1 | -- SQL table/record type upgrade file for dnsadmin 1.0 to 1.2 migration
|
---|
2 |
|
---|
3 | -- need this before we add any other bits
|
---|
4 | CREATE TABLE locations (
|
---|
5 | location character varying (4) PRIMARY KEY,
|
---|
6 | loc_id serial UNIQUE,
|
---|
7 | group_id integer NOT NULL DEFAULT 1,
|
---|
8 | iplist text NOT NULL DEFAULT '',
|
---|
9 | description character varying(40) NOT NULL DEFAULT '',
|
---|
10 | comments text NOT NULL DEFAULT ''
|
---|
11 | );
|
---|
12 |
|
---|
13 | ALTER TABLE ONLY locations
|
---|
14 | ADD CONSTRAINT "locations_group_id_fkey" FOREIGN KEY (group_id) REFERENCES groups(group_id);
|
---|
15 |
|
---|
16 | ALTER TABLE permissions ADD COLUMN location_create boolean DEFAULT false NOT NULL;
|
---|
17 | ALTER TABLE permissions ADD COLUMN location_edit boolean DEFAULT false NOT NULL;
|
---|
18 | ALTER TABLE permissions ADD COLUMN location_delete boolean DEFAULT false NOT NULL;
|
---|
19 | ALTER TABLE permissions ADD COLUMN location_view boolean DEFAULT false NOT NULL;
|
---|
20 |
|
---|
21 | -- Minor buglet; domains must be unique
|
---|
22 | -- ALTER TABLE domains ADD PRIMARY KEY (domain);
|
---|
23 |
|
---|
24 | CREATE TABLE default_rev_records (
|
---|
25 | record_id serial NOT NULL,
|
---|
26 | group_id integer DEFAULT 1 NOT NULL,
|
---|
27 | host text DEFAULT '' NOT NULL,
|
---|
28 | "type" integer DEFAULT 1 NOT NULL,
|
---|
29 | val text DEFAULT '' NOT NULL,
|
---|
30 | ttl integer DEFAULT 86400 NOT NULL,
|
---|
31 | description text
|
---|
32 | );
|
---|
33 |
|
---|
34 | COPY default_rev_records (record_id, group_id, host, "type", val, ttl, description) FROM stdin;
|
---|
35 | 1 1 hostmaster.ADMINDOMAIN:ns1.ADMINDOMAIN 6 3600:900:1048576:2560 3600
|
---|
36 | 2 1 unused-%r.ADMINDOMAIN 65283 ZONE 3600
|
---|
37 | 3 1 ns2.example.com 2 ZONE 7200 \N
|
---|
38 | 4 1 ns1.example.com 2 ZONE 7200 \N
|
---|
39 | \.
|
---|
40 |
|
---|
41 | SELECT pg_catalog.setval('default_rev_records_record_id_seq', 5, false);
|
---|
42 |
|
---|
43 | ALTER TABLE domains ADD COLUMN changed boolean DEFAULT true NOT NULL;
|
---|
44 | ALTER TABLE domains ADD COLUMN default_location character varying (4) DEFAULT '' NOT NULL;
|
---|
45 | -- ~2x performance boost iff most zones are fed to output from the cache
|
---|
46 | CREATE INDEX dom_status_index ON domains (status);
|
---|
47 |
|
---|
48 | CREATE TABLE revzones (
|
---|
49 | rdns_id serial NOT NULL,
|
---|
50 | revnet cidr NOT NULL PRIMARY KEY,
|
---|
51 | group_id integer DEFAULT 1 NOT NULL,
|
---|
52 | description character varying(255) DEFAULT ''::character varying NOT NULL,
|
---|
53 | status integer DEFAULT 1 NOT NULL,
|
---|
54 | zserial integer,
|
---|
55 | sertype character(1) DEFAULT 'D'::bpchar,
|
---|
56 | changed boolean DEFAULT true NOT NULL,
|
---|
57 | default_location character varying (4) DEFAULT '' NOT NULL
|
---|
58 | );
|
---|
59 | CREATE INDEX rev_status_index ON revzones (status);
|
---|
60 |
|
---|
61 | ALTER TABLE ONLY revzones
|
---|
62 | ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id);
|
---|
63 |
|
---|
64 | ALTER TABLE log ADD COLUMN rdns_id INTEGER;
|
---|
65 |
|
---|
66 | -- Since records are now parented by one or both of a forward or reverse zone,
|
---|
67 | -- we can't enforce FK relations on domain_id (or the new rdns_id) since many
|
---|
68 | -- records won't have one or the other.
|
---|
69 | ALTER TABLE records DROP CONSTRAINT "$1";
|
---|
70 | ALTER TABLE records ALTER COLUMN domain_id SET DEFAULT 0;
|
---|
71 | ALTER TABLE records ADD COLUMN rdns_id INTEGER DEFAULT 0 NOT NULL;
|
---|
72 | ALTER TABLE records ADD COLUMN location character varying (4) DEFAULT '' NOT NULL;
|
---|
73 |
|
---|
74 | -- ~120s -> 75s performance boost on 100K records when always exporting all records
|
---|
75 | CREATE INDEX rec_types_index ON records (type);
|
---|
76 | -- Further ~1/3 performance gain, same dataset
|
---|
77 | CREATE INDEX rec_domain_index ON records (domain_id);
|
---|
78 | CREATE INDEX rec_revzone_index ON records (rdns_id);
|
---|
79 |
|
---|
80 | -- May as well drop and recreate; this is nominally static and loaded from the
|
---|
81 | -- DB mainly for subset grouping and sorting convenience. Most of the entries
|
---|
82 | -- have also been updated with new subset grouping and sorting data.
|
---|
83 | DROP TABLE rectypes;
|
---|
84 | CREATE TABLE rectypes (
|
---|
85 | val integer NOT NULL,
|
---|
86 | name character varying(20) NOT NULL,
|
---|
87 | stdflag integer DEFAULT 1 NOT NULL,
|
---|
88 | listorder integer DEFAULT 255 NOT NULL,
|
---|
89 | alphaorder integer DEFAULT 32768 NOT NULL
|
---|
90 | );
|
---|
91 |
|
---|
92 | -- Types are required. NB: these are vaguely read-only too
|
---|
93 | -- data from http://www.iana.org/assignments/dns-parameters
|
---|
94 | COPY rectypes (val, name, stdflag, listorder, alphaorder) FROM stdin;
|
---|
95 | 1 A 1 1 1
|
---|
96 | 2 NS 2 9 37
|
---|
97 | 3 MD 5 255 29
|
---|
98 | 4 MF 5 255 30
|
---|
99 | 5 CNAME 2 11 9
|
---|
100 | 6 SOA 0 0 53
|
---|
101 | 7 MB 5 255 28
|
---|
102 | 8 MG 5 255 31
|
---|
103 | 9 MR 5 255 33
|
---|
104 | 10 NULL 5 255 43
|
---|
105 | 11 WKS 5 255 64
|
---|
106 | 12 PTR 3 5 46
|
---|
107 | 13 HINFO 5 255 18
|
---|
108 | 14 MINFO 5 255 32
|
---|
109 | 15 MX 1 10 34
|
---|
110 | 16 TXT 2 12 60
|
---|
111 | 17 RP 4 255 48
|
---|
112 | 18 AFSDB 5 255 4
|
---|
113 | 19 X25 5 255 65
|
---|
114 | 20 ISDN 5 255 21
|
---|
115 | 21 RT 5 255 50
|
---|
116 | 22 NSAP 5 255 38
|
---|
117 | 23 NSAP-PTR 5 255 39
|
---|
118 | 24 SIG 5 255 51
|
---|
119 | 25 KEY 5 255 23
|
---|
120 | 26 PX 5 255 47
|
---|
121 | 27 GPOS 5 255 17
|
---|
122 | 28 AAAA 1 3 3
|
---|
123 | 29 LOC 5 255 25
|
---|
124 | 30 NXT 5 255 44
|
---|
125 | 31 EID 5 255 15
|
---|
126 | 32 NIMLOC 5 255 36
|
---|
127 | 33 SRV 1 13 55
|
---|
128 | 34 ATMA 5 255 6
|
---|
129 | 35 NAPTR 5 255 35
|
---|
130 | 36 KX 5 255 24
|
---|
131 | 37 CERT 5 255 8
|
---|
132 | 38 A6 5 3 2
|
---|
133 | 39 DNAME 5 255 12
|
---|
134 | 40 SINK 5 255 52
|
---|
135 | 41 OPT 5 255 45
|
---|
136 | 42 APL 5 255 5
|
---|
137 | 43 DS 5 255 14
|
---|
138 | 44 SSHFP 5 255 56
|
---|
139 | 45 IPSECKEY 5 255 20
|
---|
140 | 46 RRSIG 5 255 49
|
---|
141 | 47 NSEC 5 255 40
|
---|
142 | 48 DNSKEY 5 255 13
|
---|
143 | 49 DHCID 5 255 10
|
---|
144 | 50 NSEC3 5 255 41
|
---|
145 | 51 NSEC3PARAM 5 255 42
|
---|
146 | 55 HIP 5 255 19
|
---|
147 | 99 SPF 5 255 54
|
---|
148 | 100 UINFO 5 255 62
|
---|
149 | 101 UID 5 255 61
|
---|
150 | 102 GID 5 255 16
|
---|
151 | 103 UNSPEC 5 255 63
|
---|
152 | 249 TKEY 5 255 58
|
---|
153 | 250 TSIG 5 255 59
|
---|
154 | 251 IXFR 5 255 22
|
---|
155 | 252 AXFR 5 255 7
|
---|
156 | 253 MAILB 5 255 27
|
---|
157 | 254 MAILA 5 255 26
|
---|
158 | 32768 TA 5 255 57
|
---|
159 | 32769 DLV 5 255 11
|
---|
160 | \.
|
---|
161 |
|
---|
162 | -- Custom types (ab)using the "Private use" range from 65280 to 65534
|
---|
163 | COPY rectypes (val, name, stdflag, listorder, alphaorder) FROM stdin;
|
---|
164 | 65280 A+PTR 2 2 2
|
---|
165 | 65281 AAAA+PTR 2 4 4
|
---|
166 | 65282 PTR template 3 6 2
|
---|
167 | 65283 A+PTR template 2 7 2
|
---|
168 | 65284 AAAA+PTR template 8 13 2
|
---|
169 | 65285 Delegation 2 8 2
|
---|
170 | \.
|
---|
171 |
|
---|
172 | -- Update dbversion
|
---|
173 | UPDATE misc SET value='1.2' WHERE key='dbversion';
|
---|