From 16b4923bd742e7e35645c94d6dda578e8b15c190 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Mon, 25 May 2026 11:08:06 +0700 Subject: [PATCH] fix(db): change prefix column type to TEXT in prefix_snapshot_row Updated the prefix column in the prefix_snapshot_row table from CIDR to TEXT to accommodate broader input formats. Adjusted related SQL insert statements accordingly. --- internal/repository/postgres_prefix_snapshot.go | 2 +- internal/repository/postgres_seed.go | 4 ++-- migrations/postgres/000016_prefix_snapshot.up.sql | 2 +- migrations/postgres/000017_prefix_snapshot_backfill.up.sql | 4 ++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/repository/postgres_prefix_snapshot.go b/internal/repository/postgres_prefix_snapshot.go index c9d7166..39c3dd9 100644 --- a/internal/repository/postgres_prefix_snapshot.go +++ b/internal/repository/postgres_prefix_snapshot.go @@ -86,7 +86,7 @@ func (p *Postgres) ensurePrefixSnapshot(ctx context.Context, db execQuerier, con } if _, err := db.Exec(ctx, ` INSERT INTO prefix_snapshot_row (snapshot_id, ord, prefix, community_id, source) - VALUES ($1::uuid, $2, $3::cidr, $4::uuid, $5)`, + VALUES ($1::uuid, $2, $3, $4::uuid, $5)`, snapID, i, strings.TrimSpace(pr.Prefix), comm, src); err != nil { return "", err } diff --git a/internal/repository/postgres_seed.go b/internal/repository/postgres_seed.go index e3dc45c..125c9de 100644 --- a/internal/repository/postgres_seed.go +++ b/internal/repository/postgres_seed.go @@ -97,8 +97,8 @@ protocol direct { } if _, err := tx.Exec(ctx, ` INSERT INTO prefix_snapshot_row (snapshot_id, ord, prefix, community_id, source) - VALUES ($1::uuid, 0, '203.0.113.0/24'::cidr, $2::uuid, 'demo'), - ($1::uuid, 1, '2001:db8::/32'::cidr, $2::uuid, 'demo')`, snapID, cid); err != nil { + VALUES ($1::uuid, 0, '203.0.113.0/24', $2::uuid, 'demo'), + ($1::uuid, 1, '2001:db8::/32', $2::uuid, 'demo')`, snapID, cid); err != nil { return err } if _, err := tx.Exec(ctx, ` diff --git a/migrations/postgres/000016_prefix_snapshot.up.sql b/migrations/postgres/000016_prefix_snapshot.up.sql index 3e0efce..f542af7 100644 --- a/migrations/postgres/000016_prefix_snapshot.up.sql +++ b/migrations/postgres/000016_prefix_snapshot.up.sql @@ -10,7 +10,7 @@ CREATE TABLE prefix_snapshot ( 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, + prefix TEXT NOT NULL, community_id UUID REFERENCES bgp_community (id) ON DELETE SET NULL, source TEXT NOT NULL DEFAULT '', PRIMARY KEY (snapshot_id, ord) diff --git a/migrations/postgres/000017_prefix_snapshot_backfill.up.sql b/migrations/postgres/000017_prefix_snapshot_backfill.up.sql index ba1f3c4..910ce27 100644 --- a/migrations/postgres/000017_prefix_snapshot_backfill.up.sql +++ b/migrations/postgres/000017_prefix_snapshot_backfill.up.sql @@ -1,4 +1,8 @@ -- Backfill prefix snapshots from revision_materialized_prefix. +-- prefix_snapshot_row.prefix is TEXT (revision_materialized_prefix.prefix since 000003). + +ALTER TABLE prefix_snapshot_row + ALTER COLUMN prefix TYPE TEXT USING prefix::text; WITH new_snaps AS ( INSERT INTO prefix_snapshot (id, content_hash)