diff --git a/migrations/postgres/000016_prefix_snapshot.down.sql b/migrations/postgres/000016_prefix_snapshot.down.sql new file mode 100644 index 0000000..3ec1edd --- /dev/null +++ b/migrations/postgres/000016_prefix_snapshot.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE config_revision DROP COLUMN IF EXISTS prefix_snapshot_id; +DROP TABLE IF EXISTS prefix_snapshot_row; +DROP TABLE IF EXISTS prefix_snapshot; diff --git a/migrations/postgres/000016_prefix_snapshot.up.sql b/migrations/postgres/000016_prefix_snapshot.up.sql new file mode 100644 index 0000000..3e0efce --- /dev/null +++ b/migrations/postgres/000016_prefix_snapshot.up.sql @@ -0,0 +1,22 @@ +-- Content-addressed prefix snapshots (H2 expand). + +CREATE TABLE prefix_snapshot ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + content_hash CHAR(64) NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + CONSTRAINT prefix_snapshot_hash_uniq UNIQUE (content_hash) +); + +CREATE TABLE prefix_snapshot_row ( + snapshot_id UUID NOT NULL REFERENCES prefix_snapshot (id) ON DELETE CASCADE, + ord INTEGER NOT NULL, + prefix CIDR NOT NULL, + community_id UUID REFERENCES bgp_community (id) ON DELETE SET NULL, + source TEXT NOT NULL DEFAULT '', + PRIMARY KEY (snapshot_id, ord) +); + +CREATE INDEX idx_prefix_snapshot_row_snapshot ON prefix_snapshot_row (snapshot_id); + +ALTER TABLE config_revision + ADD COLUMN prefix_snapshot_id UUID REFERENCES prefix_snapshot (id) ON DELETE RESTRICT; diff --git a/migrations/sqlite/000016_prefix_snapshot.down.sql b/migrations/sqlite/000016_prefix_snapshot.down.sql new file mode 100644 index 0000000..6bfe79c --- /dev/null +++ b/migrations/sqlite/000016_prefix_snapshot.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE config_revision DROP COLUMN prefix_snapshot_id; +DROP TABLE IF EXISTS prefix_snapshot_row; +DROP TABLE IF EXISTS prefix_snapshot; diff --git a/migrations/sqlite/000016_prefix_snapshot.up.sql b/migrations/sqlite/000016_prefix_snapshot.up.sql new file mode 100644 index 0000000..3969a45 --- /dev/null +++ b/migrations/sqlite/000016_prefix_snapshot.up.sql @@ -0,0 +1,18 @@ +CREATE TABLE prefix_snapshot ( + id TEXT NOT NULL PRIMARY KEY, + content_hash TEXT NOT NULL UNIQUE, + created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) +); + +CREATE TABLE prefix_snapshot_row ( + snapshot_id TEXT NOT NULL REFERENCES prefix_snapshot (id) ON DELETE CASCADE, + ord INTEGER NOT NULL, + prefix TEXT NOT NULL, + community_id TEXT, + source TEXT NOT NULL DEFAULT '', + PRIMARY KEY (snapshot_id, ord) +); + +CREATE INDEX idx_prefix_snapshot_row_snapshot ON prefix_snapshot_row (snapshot_id); + +ALTER TABLE config_revision ADD COLUMN prefix_snapshot_id TEXT REFERENCES prefix_snapshot (id) ON DELETE RESTRICT;