1 | -- Baseline SQL to add necessary fields for IPDB 2.7 -> IPDB 3.0
|
---|
2 | -- Note some data changes must be made via script.
|
---|
3 |
|
---|
4 | -- WARNING: This SQL is backwards-compatible, but once db-update.pl
|
---|
5 | -- has run, IPDB v2.7 and older will NOT be able to properly manipulate
|
---|
6 | -- the data!
|
---|
7 |
|
---|
8 | -- Flag table for deciding if we can usefully do rDNS RPC calls.
|
---|
9 | CREATE TABLE dnsavail (
|
---|
10 | "zone" cidr PRIMARY KEY,
|
---|
11 | "location" varchar(2) DEFAULT '',
|
---|
12 | parent_alloc integer NOT NULL
|
---|
13 | );
|
---|
14 |
|
---|
15 | -- Store backup fields in a separate table
|
---|
16 | CREATE TABLE backuplist (
|
---|
17 | backup_id serial NOT NULL,
|
---|
18 | bkbrand text,
|
---|
19 | bkmodel text,
|
---|
20 | bktype text,
|
---|
21 | bkport integer,
|
---|
22 | bksrc text,
|
---|
23 | bkuser text,
|
---|
24 | bkvpass text,
|
---|
25 | bkepass text,
|
---|
26 | ip inet
|
---|
27 | );
|
---|
28 |
|
---|
29 | -- Master and routed blocks now live in the allocations table.
|
---|
30 |
|
---|
31 | ALTER TABLE allocations ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
32 | ALTER TABLE allocations ADD COLUMN vlan text NOT NULL DEFAULT '';
|
---|
33 | ALTER TABLE allocations ADD COLUMN rdns text NOT NULL DEFAULT '';
|
---|
34 | ALTER TABLE allocations ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
35 | ALTER TABLE allocations ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
36 | ALTER TABLE allocations ADD COLUMN backup_id integer NOT NULL DEFAULT 0;
|
---|
37 | ALTER TABLE allocations DROP CONSTRAINT allocations_pkey;
|
---|
38 | ALTER TABLE allocations ADD COLUMN id serial PRIMARY KEY;
|
---|
39 | -- not certain this is right
|
---|
40 | CREATE UNIQUE INDEX allocations_skey ON allocations (cidr,vrf,type);
|
---|
41 |
|
---|
42 | ALTER TABLE freeblocks ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
43 | ALTER TABLE freeblocks ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
44 | ALTER TABLE freeblocks ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
45 | ALTER TABLE freeblocks ADD COLUMN reserve_for integer NOT NULL DEFAULT 0;
|
---|
46 | ALTER TABLE freeblocks DROP CONSTRAINT freeblocks_pkey;
|
---|
47 | ALTER TABLE freeblocks ADD CONSTRAINT freeblocks_pkey PRIMARY KEY ("cidr","parent_id");
|
---|
48 | ALTER TABLE freeblocks ADD COLUMN id serial;
|
---|
49 |
|
---|
50 | ALTER TABLE poolips ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
51 | ALTER TABLE poolips ADD COLUMN vlan text NOT NULL DEFAULT '';
|
---|
52 | ALTER TABLE poolips ADD COLUMN rdns text NOT NULL DEFAULT '';
|
---|
53 | ALTER TABLE poolips ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
54 | ALTER TABLE poolips ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
55 | ALTER TABLE poolips ADD COLUMN backup_id integer NOT NULL DEFAULT 0;
|
---|
56 | ALTER TABLE poolips DROP CONSTRAINT poolips_pkey;
|
---|
57 | ALTER TABLE poolips ADD COLUMN id serial;
|
---|
58 | ALTER TABLE poolips ADD CONSTRAINT poolips_pkey PRIMARY KEY ("ip", "parent_id");
|
---|
59 |
|
---|
60 | -- probably need some more indexes
|
---|
61 |
|
---|
62 | -- Need some additional fields to support search output. Might arguably
|
---|
63 | -- move pool IPs into the allocations table; we'll see.
|
---|
64 | DROP VIEW searchme;
|
---|
65 | -- do these here, because we can't do them while the view is defined
|
---|
66 | ALTER TABLE allocations ALTER COLUMN description TYPE varchar(128);
|
---|
67 | ALTER TABLE poolips ALTER COLUMN description TYPE varchar(128);
|
---|
68 | CREATE VIEW "searchme" AS
|
---|
69 | SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city,
|
---|
70 | allocations.description, allocations.notes, allocations.circuitid, allocations.vrf,
|
---|
71 | allocations.vlan, allocations.id, allocations.parent_id, 'n' AS available
|
---|
72 | FROM allocations
|
---|
73 | UNION
|
---|
74 | SELECT poolips.ip, poolips.custid, poolips.type, poolips.city,
|
---|
75 | poolips.description, poolips.notes, poolips.circuitid, poolips.vrf,
|
---|
76 | poolips.vlan, poolips.id, poolips.parent_id, poolips.available
|
---|
77 | FROM poolips;
|
---|
78 |
|
---|
79 | -- Relabel a few types to match the new structure
|
---|
80 | UPDATE alloctypes SET listname='Routing aggregation', dispname='Routing aggregation' WHERE type='rm';
|
---|
81 |
|
---|
82 | -- Not critical but the previous definitions were too restrictive (eg, can't
|
---|
83 | -- handle MD5, or SHA password hashes). Plans for ACLs also require larger fields.
|
---|
84 | ALTER TABLE users ALTER COLUMN username TYPE varchar(256);
|
---|
85 | ALTER TABLE users ALTER COLUMN password TYPE varchar(256);
|
---|
86 | ALTER TABLE users ALTER COLUMN acl TYPE varchar(256);
|
---|