source: trunk/cgi-bin/ipdb-2.7-3.0.sql@ 679

Last change on this file since 679 was 670, checked in by Kris Deugau, 10 years ago

/trunk

Minimally update search tool for new database layout. Still needs a major rewrite.

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