[658] | 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 |
|
---|
[762] | 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 |
|
---|
[658] | 15 | -- Master and routed blocks now live in the allocations table.
|
---|
| 16 |
|
---|
| 17 | ALTER TABLE allocations ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
[691] | 18 | ALTER TABLE allocations ADD COLUMN vlan text NOT NULL DEFAULT '';
|
---|
[658] | 19 | ALTER TABLE allocations ADD COLUMN rdns text NOT NULL DEFAULT '';
|
---|
| 20 | ALTER TABLE allocations ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
| 21 | ALTER TABLE allocations ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
| 22 | ALTER TABLE allocations DROP CONSTRAINT allocations_pkey;
|
---|
| 23 | ALTER TABLE allocations ADD COLUMN id serial PRIMARY KEY;
|
---|
[762] | 24 | CREATE UNIQUE INDEX allocations_skey ON allocations (cidr,vrf,type);
|
---|
[658] | 25 |
|
---|
| 26 | ALTER TABLE freeblocks ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
| 27 | ALTER TABLE freeblocks ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
| 28 | ALTER TABLE freeblocks ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
[762] | 29 | ALTER TABLE freeblocks ADD COLUMN reserve_for integer NOT NULL DEFAULT 0;
|
---|
[658] | 30 | ALTER TABLE freeblocks DROP CONSTRAINT freeblocks_pkey;
|
---|
| 31 | ALTER TABLE freeblocks ADD CONSTRAINT freeblocks_pkey PRIMARY KEY ("cidr","parent_id");
|
---|
| 32 | ALTER TABLE freeblocks ADD COLUMN id serial;
|
---|
| 33 |
|
---|
| 34 | ALTER TABLE poolips ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
[691] | 35 | ALTER TABLE poolips ADD COLUMN vlan text NOT NULL DEFAULT '';
|
---|
[658] | 36 | ALTER TABLE poolips ADD COLUMN rdns text NOT NULL DEFAULT '';
|
---|
| 37 | ALTER TABLE poolips ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
| 38 | ALTER TABLE poolips ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
| 39 | ALTER TABLE poolips DROP CONSTRAINT poolips_pkey;
|
---|
| 40 | ALTER TABLE poolips ADD COLUMN id serial;
|
---|
| 41 | ALTER TABLE poolips ADD CONSTRAINT poolips_pkey PRIMARY KEY ("ip", "parent_id");
|
---|
| 42 |
|
---|
| 43 | -- probably need some more indexes
|
---|
| 44 |
|
---|
[670] | 45 | -- Need some additional fields to support search output. Might arguably
|
---|
| 46 | -- move pool IPs into the allocations table; we'll see.
|
---|
| 47 | DROP VIEW searchme;
|
---|
| 48 | CREATE VIEW "searchme" AS
|
---|
| 49 | SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city,
|
---|
[691] | 50 | allocations.description, allocations.notes, allocations.circuitid, allocations.vrf,
|
---|
| 51 | allocations.vlan, allocations.id, allocations.parent_id, 'n' AS available
|
---|
[670] | 52 | FROM allocations
|
---|
| 53 | UNION
|
---|
| 54 | SELECT poolips.ip, poolips.custid, poolips.type, poolips.city,
|
---|
[691] | 55 | poolips.description, poolips.notes, poolips.circuitid, poolips.vrf,
|
---|
| 56 | poolips.vlan, poolips.id, poolips.parent_id, poolips.available
|
---|
[670] | 57 | FROM poolips;
|
---|
| 58 |
|
---|
[658] | 59 | -- Relabel a few types to match the new structure
|
---|
| 60 | UPDATE alloctypes SET listname='Routing aggregation', dispname='Routing aggregation' WHERE type='rm';
|
---|
| 61 |
|
---|
| 62 | -- Not critical but the previous definitions were too restrictive (eg, can't
|
---|
| 63 | -- handle MD5, or SHA password hashes). Plans for ACLs also require larger fields.
|
---|
| 64 | ALTER TABLE users ALTER COLUMN username TYPE varchar(256);
|
---|
| 65 | ALTER TABLE users ALTER COLUMN password TYPE varchar(256);
|
---|
| 66 | ALTER TABLE users ALTER COLUMN acl TYPE varchar(256);
|
---|