From e4d1e501cfd8f14ea9fe9c1e422b7b943134a7e6 Mon Sep 17 00:00:00 2001 From: Todd Date: Tue, 15 Feb 2022 15:49:41 -0700 Subject: [PATCH] fix(warehouse): Handle duplicate addresses when migrating into wh_network_address_dimension (#1860) --- .../oss/postgres/26/01_wh_network_address_dimensions.up.sql | 4 ++-- internal/db/schema/migrations/oss/postgres_26_01_test.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/db/schema/migrations/oss/postgres/26/01_wh_network_address_dimensions.up.sql b/internal/db/schema/migrations/oss/postgres/26/01_wh_network_address_dimensions.up.sql index 46bf01f8e..87ce20c0e 100644 --- a/internal/db/schema/migrations/oss/postgres/26/01_wh_network_address_dimensions.up.sql +++ b/internal/db/schema/migrations/oss/postgres/26/01_wh_network_address_dimensions.up.sql @@ -108,7 +108,7 @@ begin; ip4_address, ip6_address ) - select + select distinct address, 'IP Address', case @@ -135,7 +135,7 @@ begin; dns_name, ip4_address, ip6_address ) - select + select distinct whd.host_address, 'DNS Name', 'Not Applicable', 'Not Applicable', whd.host_address, diff --git a/internal/db/schema/migrations/oss/postgres_26_01_test.go b/internal/db/schema/migrations/oss/postgres_26_01_test.go index 1866e8c58..c6f1b9f8f 100644 --- a/internal/db/schema/migrations/oss/postgres_26_01_test.go +++ b/internal/db/schema/migrations/oss/postgres_26_01_test.go @@ -185,6 +185,11 @@ values _, err := rw.Exec(ctx, q, []interface{}{a.Address}) require.NoError(t, err) } + // Duplicate a few records... + _, err := rw.Exec(ctx, q, []interface{}{addresses[1].Address}) + require.NoError(t, err) + _, err = rw.Exec(ctx, q, []interface{}{addresses[5].Address}) + require.NoError(t, err) } // now we're ready for the migration we want to test.