Sergiusz Bazanski | 1fad2e5 | 2019-08-01 20:16:27 +0200 | [diff] [blame] | 1 | CREATE TABLE peers ( |
| 2 | id UUID PRIMARY KEY DEFAULT gen_random_uuid(), |
| 3 | asn STRING NOT NULL, |
| 4 | name STRING NOT NULL, |
| 5 | source STRING check ( |
| 6 | source = 'from-peeringdb' or |
| 7 | source = 'manual' |
| 8 | ) NOT NULL, |
| 9 | UNIQUE (asn) |
| 10 | ); |
| 11 | |
| 12 | CREATE TABLE peer_routers ( |
| 13 | peer_id UUID NOT NULL, |
| 14 | id UUID DEFAULT gen_random_uuid(), |
| 15 | |
| 16 | v6 STRING, |
| 17 | v4 STRING, |
| 18 | source STRING check ( |
| 19 | source = 'from-peeringdb' or |
| 20 | source = 'manual' |
| 21 | ) NOT NULL, |
| 22 | |
| 23 | UNIQUE (v4), |
| 24 | UNIQUE (v6), |
| 25 | PRIMARY KEY (peer_id, id), |
| 26 | CONSTRAINT fk_peer FOREIGN KEY (peer_id) REFERENCES peers (id) ON DELETE CASCADE |
| 27 | ) INTERLEAVE IN PARENT peers (peer_id); |