diff --git a/satellite/satellitedb/migrate.go b/satellite/satellitedb/migrate.go index 477469981..c15d81e0e 100644 --- a/satellite/satellitedb/migrate.go +++ b/satellite/satellitedb/migrate.go @@ -554,6 +554,12 @@ func (db *DB) PostgresMigration() *migrate.Migration { Version: 16, Action: migrate.Func(func(log *zap.Logger, db migrate.DB, tx *sql.Tx) error { _, 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 RENAME COLUMN info TO data; ALTER TABLE injuredsegments ADD attempted timestamp; diff --git a/satellite/satellitedb/repairqueue_test.go b/satellite/satellitedb/repairqueue_test.go index 1f4cd3dd8..63381b87a 100644 --- a/satellite/satellitedb/repairqueue_test.go +++ b/satellite/satellitedb/repairqueue_test.go @@ -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) { satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) { ctx := testcontext.New(t) diff --git a/satellite/satellitedb/testdata/postgres.v15.sql b/satellite/satellitedb/testdata/postgres.v15.sql index bd65f49eb..39dcaf53b 100644 --- a/satellite/satellitedb/testdata/postgres.v15.sql +++ b/satellite/satellitedb/testdata/postgres.v15.sql @@ -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 (3, '\x0a157965742f616e6f746865722f636f6f6c2f70617468120a0102030405060708090a'); INSERT INTO "injuredsegments" ("id", "info") VALUES (4, '\x0a23736f2f6d616e792f69636f6e69632f70617468732f746f2f63686f6f73652f66726f6d120a0102030405060708090a'); +INSERT INTO "injuredsegments" ("id", "info") VALUES (5, '\x0a23736f2f6d616e792f69636f6e69632f70617468732f746f2f63686f6f73652f66726f6d120a0102030405060708090a');