[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 (
|
---|
[865] | 10 | "zone" cidr,
|
---|
[854] | 11 | "location" varchar(4) DEFAULT '',
|
---|
[762] | 12 | parent_alloc integer NOT NULL
|
---|
| 13 | );
|
---|
| 14 |
|
---|
[865] | 15 | ALTER TABLE ONLY dnsavail
|
---|
| 16 | ADD CONSTRAINT dnsavail_pkey PRIMARY KEY ("zone",parent_alloc);
|
---|
| 17 |
|
---|
[779] | 18 | -- Store backup fields in a separate table
|
---|
| 19 | CREATE TABLE backuplist (
|
---|
| 20 | backup_id serial NOT NULL,
|
---|
| 21 | bkbrand text,
|
---|
| 22 | bkmodel text,
|
---|
| 23 | bktype text,
|
---|
| 24 | bkport integer,
|
---|
| 25 | bksrc text,
|
---|
| 26 | bkuser text,
|
---|
| 27 | bkvpass text,
|
---|
| 28 | bkepass text,
|
---|
[794] | 29 | bkip inet
|
---|
[779] | 30 | );
|
---|
| 31 |
|
---|
[807] | 32 | -- VRFs are now the apex entity
|
---|
| 33 | CREATE TABLE vrfs (
|
---|
| 34 | vrf varchar(32) DEFAULT '' NOT NULL,
|
---|
| 35 | comment text DEFAULT '' NOT NULL,
|
---|
| 36 | location varchar(4) DEFAULT '' NOT NULL
|
---|
| 37 | );
|
---|
| 38 |
|
---|
| 39 | ALTER TABLE ONLY vrfs
|
---|
| 40 | ADD CONSTRAINT vrfs_pkey PRIMARY KEY (vrf);
|
---|
| 41 |
|
---|
| 42 | -- need a default VRF to stuff everything into to start with
|
---|
| 43 | INSERT INTO vrfs (vrf,comment) VALUES ('DEFAULT','Initial default VRF');
|
---|
| 44 |
|
---|
[658] | 45 | -- Master and routed blocks now live in the allocations table.
|
---|
| 46 |
|
---|
| 47 | ALTER TABLE allocations ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
[691] | 48 | ALTER TABLE allocations ADD COLUMN vlan text NOT NULL DEFAULT '';
|
---|
[658] | 49 | ALTER TABLE allocations ADD COLUMN rdns text NOT NULL DEFAULT '';
|
---|
| 50 | ALTER TABLE allocations ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
| 51 | ALTER TABLE allocations ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
[779] | 52 | ALTER TABLE allocations ADD COLUMN backup_id integer NOT NULL DEFAULT 0;
|
---|
[658] | 53 | ALTER TABLE allocations DROP CONSTRAINT allocations_pkey;
|
---|
| 54 | ALTER TABLE allocations ADD COLUMN id serial PRIMARY KEY;
|
---|
[779] | 55 | -- not certain this is right
|
---|
[762] | 56 | CREATE UNIQUE INDEX allocations_skey ON allocations (cidr,vrf,type);
|
---|
[658] | 57 |
|
---|
| 58 | ALTER TABLE freeblocks ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
| 59 | ALTER TABLE freeblocks ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
| 60 | ALTER TABLE freeblocks ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
[762] | 61 | ALTER TABLE freeblocks ADD COLUMN reserve_for integer NOT NULL DEFAULT 0;
|
---|
[658] | 62 | ALTER TABLE freeblocks DROP CONSTRAINT freeblocks_pkey;
|
---|
| 63 | ALTER TABLE freeblocks ADD CONSTRAINT freeblocks_pkey PRIMARY KEY ("cidr","parent_id");
|
---|
| 64 | ALTER TABLE freeblocks ADD COLUMN id serial;
|
---|
| 65 |
|
---|
| 66 | ALTER TABLE poolips ADD COLUMN vrf text NOT NULL DEFAULT '';
|
---|
[691] | 67 | ALTER TABLE poolips ADD COLUMN vlan text NOT NULL DEFAULT '';
|
---|
[658] | 68 | ALTER TABLE poolips ADD COLUMN rdns text NOT NULL DEFAULT '';
|
---|
| 69 | ALTER TABLE poolips ADD COLUMN parent_id integer NOT NULL DEFAULT 0;
|
---|
| 70 | ALTER TABLE poolips ADD COLUMN master_id integer NOT NULL DEFAULT 0;
|
---|
[779] | 71 | ALTER TABLE poolips ADD COLUMN backup_id integer NOT NULL DEFAULT 0;
|
---|
[658] | 72 | ALTER TABLE poolips DROP CONSTRAINT poolips_pkey;
|
---|
| 73 | ALTER TABLE poolips ADD COLUMN id serial;
|
---|
| 74 | ALTER TABLE poolips ADD CONSTRAINT poolips_pkey PRIMARY KEY ("ip", "parent_id");
|
---|
| 75 |
|
---|
| 76 | -- probably need some more indexes
|
---|
| 77 |
|
---|
[670] | 78 | -- Need some additional fields to support search output. Might arguably
|
---|
| 79 | -- move pool IPs into the allocations table; we'll see.
|
---|
| 80 | DROP VIEW searchme;
|
---|
[792] | 81 | -- do these here, because we can't do them while the view is defined
|
---|
| 82 | ALTER TABLE allocations ALTER COLUMN description TYPE varchar(128);
|
---|
| 83 | ALTER TABLE poolips ALTER COLUMN description TYPE varchar(128);
|
---|
[670] | 84 | CREATE VIEW "searchme" AS
|
---|
| 85 | SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city,
|
---|
[691] | 86 | allocations.description, allocations.notes, allocations.circuitid, allocations.vrf,
|
---|
[824] | 87 | allocations.vlan, allocations.id, allocations.parent_id, allocations.master_id, 'n' AS available
|
---|
[670] | 88 | FROM allocations
|
---|
| 89 | UNION
|
---|
| 90 | SELECT poolips.ip, poolips.custid, poolips.type, poolips.city,
|
---|
[691] | 91 | poolips.description, poolips.notes, poolips.circuitid, poolips.vrf,
|
---|
[824] | 92 | poolips.vlan, poolips.id, poolips.parent_id, poolips.master_id, poolips.available
|
---|
[670] | 93 | FROM poolips;
|
---|
| 94 |
|
---|
[658] | 95 | -- Relabel a few types to match the new structure
|
---|
| 96 | UPDATE alloctypes SET listname='Routing aggregation', dispname='Routing aggregation' WHERE type='rm';
|
---|
| 97 |
|
---|
| 98 | -- Not critical but the previous definitions were too restrictive (eg, can't
|
---|
| 99 | -- handle MD5, or SHA password hashes). Plans for ACLs also require larger fields.
|
---|
| 100 | ALTER TABLE users ALTER COLUMN username TYPE varchar(256);
|
---|
| 101 | ALTER TABLE users ALTER COLUMN password TYPE varchar(256);
|
---|
| 102 | ALTER TABLE users ALTER COLUMN acl TYPE varchar(256);
|
---|