CREATE TABLE peers (
        id  UUID PRIMARY KEY DEFAULT gen_random_uuid(),
        asn STRING NOT NULL,
        name STRING NOT NULL,
        source STRING check (
            source = 'from-peeringdb' or
            source = 'manual'
        ) NOT NULL,
        UNIQUE (asn)
);

CREATE TABLE peer_routers (
        peer_id UUID NOT NULL,
        id UUID DEFAULT gen_random_uuid(),

        v6 STRING,
        v4 STRING,
        source STRING check (
            source = 'from-peeringdb' or
            source = 'manual'
        ) NOT NULL,

        UNIQUE (v4),
        UNIQUE (v6),
        PRIMARY KEY (peer_id, id),
        CONSTRAINT fk_peer FOREIGN KEY (peer_id) REFERENCES peers (id) ON DELETE CASCADE
) INTERLEAVE IN PARENT peers (peer_id);
