fixes issue where both 36 byte and 16 uuids have duplicate time entries after deploying new version with 16 byte uuid (#2450)

This commit is contained in:
ethanadams 2019-07-04 15:25:34 -04:00 committed by GitHub
parent 945513517c
commit 537c6021d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;`,
},