deletes duplicates from existing injuredsegments table (#1781)

This commit is contained in:
Natalie Villasana 2019-04-22 12:41:53 -04:00 committed by GitHub
parent 05732416dc
commit 37d95f164c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -554,6 +554,12 @@ func (db *DB) PostgresMigration() *migrate.Migration {
Version: 16, Version: 16,
Action: migrate.Func(func(log *zap.Logger, db migrate.DB, tx *sql.Tx) error { Action: migrate.Func(func(log *zap.Logger, db migrate.DB, tx *sql.Tx) error {
_, err := tx.Exec(` _, err := tx.Exec(`
DELETE FROM injuredsegments a USING injuredsegments b WHERE a.id < b.id AND a.info = b.info;
`)
if err != nil {
return ErrMigrate.Wrap(err)
}
_, err = tx.Exec(`
ALTER TABLE injuredsegments ADD path text; ALTER TABLE injuredsegments ADD path text;
ALTER TABLE injuredsegments RENAME COLUMN info TO data; ALTER TABLE injuredsegments RENAME COLUMN info TO data;
ALTER TABLE injuredsegments ADD attempted timestamp; ALTER TABLE injuredsegments ADD attempted timestamp;

View File

@ -39,6 +39,24 @@ func TestInsertSelect(t *testing.T) {
}) })
} }
func TestInsertDuplicate(t *testing.T) {
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
q := db.RepairQueue()
seg := &pb.InjuredSegment{
Path: "abc",
LostPieces: []int32{int32(1), int32(3)},
}
err := q.Insert(ctx, seg)
require.NoError(t, err)
err = q.Insert(ctx, seg)
require.NoError(t, err)
})
}
func TestDequeueEmptyQueue(t *testing.T) { func TestDequeueEmptyQueue(t *testing.T) {
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) { satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
ctx := testcontext.New(t) ctx := testcontext.New(t)

View File

@ -236,3 +236,4 @@ INSERT INTO "bucket_storage_tallies" ("bucket_name", "project_id", "interval_sta
INSERT INTO "injuredsegments" ("id", "info") VALUES (2, '\x0a136865726527732f612f67726561742f70617468120a0102030405060708090a'); INSERT INTO "injuredsegments" ("id", "info") VALUES (2, '\x0a136865726527732f612f67726561742f70617468120a0102030405060708090a');
INSERT INTO "injuredsegments" ("id", "info") VALUES (3, '\x0a157965742f616e6f746865722f636f6f6c2f70617468120a0102030405060708090a'); INSERT INTO "injuredsegments" ("id", "info") VALUES (3, '\x0a157965742f616e6f746865722f636f6f6c2f70617468120a0102030405060708090a');
INSERT INTO "injuredsegments" ("id", "info") VALUES (4, '\x0a23736f2f6d616e792f69636f6e69632f70617468732f746f2f63686f6f73652f66726f6d120a0102030405060708090a'); INSERT INTO "injuredsegments" ("id", "info") VALUES (4, '\x0a23736f2f6d616e792f69636f6e69632f70617468732f746f2f63686f6f73652f66726f6d120a0102030405060708090a');
INSERT INTO "injuredsegments" ("id", "info") VALUES (5, '\x0a23736f2f6d616e792f69636f6e69632f70617468732f746f2f63686f6f73652f66726f6d120a0102030405060708090a');