Major schema refactoring: simplify ASN and prefix tracking
- Remove UUID primary keys from ASNs table, use ASN number as primary key - Update announcements table to reference ASN numbers directly - Rename asns.number column to asns.asn for consistency - Add prefix tracking to PrefixHandler to populate prefixes_v4/v6 tables - Add UpdatePrefixesBatch method for efficient batch updates - Update all database methods and models to use new schema - Fix all references in code to use ASN field instead of Number - Update test mocks to match new interfaces
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
-- DO NOT make schema changes anywhere else in the codebase.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS asns (
|
||||
id TEXT PRIMARY KEY,
|
||||
number INTEGER UNIQUE NOT NULL,
|
||||
asn INTEGER PRIMARY KEY,
|
||||
handle TEXT,
|
||||
description TEXT,
|
||||
first_seen DATETIME NOT NULL,
|
||||
@@ -30,15 +29,14 @@ CREATE TABLE IF NOT EXISTS prefixes_v6 (
|
||||
CREATE TABLE IF NOT EXISTS announcements (
|
||||
id TEXT PRIMARY KEY,
|
||||
prefix_id TEXT NOT NULL,
|
||||
asn_id TEXT NOT NULL,
|
||||
origin_asn_id TEXT NOT NULL,
|
||||
peer_asn INTEGER NOT NULL,
|
||||
origin_asn INTEGER NOT NULL,
|
||||
path TEXT NOT NULL,
|
||||
next_hop TEXT,
|
||||
timestamp DATETIME NOT NULL,
|
||||
is_withdrawal BOOLEAN NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY (prefix_id) REFERENCES prefixes(id),
|
||||
FOREIGN KEY (asn_id) REFERENCES asns(id),
|
||||
FOREIGN KEY (origin_asn_id) REFERENCES asns(id)
|
||||
FOREIGN KEY (peer_asn) REFERENCES asns(asn),
|
||||
FOREIGN KEY (origin_asn) REFERENCES asns(asn)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS peerings (
|
||||
@@ -67,13 +65,14 @@ CREATE INDEX IF NOT EXISTS idx_prefixes_v4_prefix ON prefixes_v4(prefix);
|
||||
CREATE INDEX IF NOT EXISTS idx_prefixes_v6_prefix ON prefixes_v6(prefix);
|
||||
CREATE INDEX IF NOT EXISTS idx_announcements_timestamp ON announcements(timestamp);
|
||||
CREATE INDEX IF NOT EXISTS idx_announcements_prefix_id ON announcements(prefix_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_announcements_asn_id ON announcements(asn_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_announcements_peer_asn ON announcements(peer_asn);
|
||||
CREATE INDEX IF NOT EXISTS idx_announcements_origin_asn ON announcements(origin_asn);
|
||||
CREATE INDEX IF NOT EXISTS idx_peerings_as_a ON peerings(as_a);
|
||||
CREATE INDEX IF NOT EXISTS idx_peerings_as_b ON peerings(as_b);
|
||||
CREATE INDEX IF NOT EXISTS idx_peerings_lookup ON peerings(as_a, as_b);
|
||||
|
||||
-- Indexes for asns table
|
||||
CREATE INDEX IF NOT EXISTS idx_asns_number ON asns(number);
|
||||
CREATE INDEX IF NOT EXISTS idx_asns_asn ON asns(asn);
|
||||
|
||||
-- Indexes for bgp_peers table
|
||||
CREATE INDEX IF NOT EXISTS idx_bgp_peers_asn ON bgp_peers(peer_asn);
|
||||
|
||||
Reference in New Issue
Block a user