From 537c6021d5f6a8e8f48106cbeafd2fdb9420543e Mon Sep 17 00:00:00 2001 From: ethanadams Date: Thu, 4 Jul 2019 15:25:34 -0400 Subject: [PATCH] fixes issue where both 36 byte and 16 uuids have duplicate time entries after deploying new version with 16 byte uuid (#2450) --- satellite/satellitedb/migrate.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/satellite/satellitedb/migrate.go b/satellite/satellitedb/migrate.go index c410ce172..8ab09f085 100644 --- a/satellite/satellitedb/migrate.go +++ b/satellite/satellitedb/migrate.go @@ -870,6 +870,28 @@ func (db *DB) PostgresMigration() *migrate.Migration { Description: "Update project_id column from 36 byte string based UUID to 16 byte UUID", Version: 37, Action: migrate.SQL{ + ` + update bucket_bandwidth_rollups as a + set allocated = a.allocated + b.allocated, + settled = a.settled + b.settled + from bucket_bandwidth_rollups as b + where a.interval_start = b.interval_start + and a.bucket_name = b.bucket_name + and a.action = b.action + and a.project_id = decode(replace(encode(b.project_id, 'escape'), '-', ''), 'hex') + and length(b.project_id) = 36 + and length(a.project_id) = 16 + ;`, + ` + delete from bucket_bandwidth_rollups as b + using bucket_bandwidth_rollups as a + where a.interval_start = b.interval_start + and a.bucket_name = b.bucket_name + and a.action = b.action + and a.project_id = decode(replace(encode(b.project_id, 'escape'), '-', ''), 'hex') + and length(b.project_id) = 36 + and length(a.project_id) = 16 + ;`, `UPDATE bucket_storage_tallies SET project_id = decode(replace(encode(project_id, 'escape'), '-', ''), 'hex') WHERE length(project_id) = 36;`, `UPDATE bucket_bandwidth_rollups SET project_id = decode(replace(encode(project_id, 'escape'), '-', ''), 'hex') WHERE length(project_id) = 36;`, },