Skip to content

Commit b660eab

Browse files
Merge pull request #669 from njhale/fix/migration-12
fix(sqlite): upsert deprecation table entries
2 parents 92e5523 + 5b9db62 commit b660eab

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

pkg/sqlite/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ func (s *sqlLoader) DeprecateBundle(path string) error {
14571457

14581458
// Create a persistent record of the bundle's deprecation
14591459
// This lets us recover from losing the properties and augmented bundle rows
1460-
_, err = tx.Exec("INSERT INTO deprecated(operatorbundle_name) VALUES(?)", name)
1460+
_, err = tx.Exec("INSERT OR REPLACE INTO deprecated(operatorbundle_name) VALUES(?)", name)
14611461
if err != nil {
14621462
return err
14631463
}

pkg/sqlite/migrations/012_deprecated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var deprecatedMigration = &Migration{
2929
return err
3030
}
3131

32-
initDeprecated := fmt.Sprintf(`INSERT INTO deprecated(operatorbundle_name) SELECT operatorbundle_name FROM properties WHERE properties.type='%s'`, registry.DeprecatedType)
32+
initDeprecated := fmt.Sprintf(`INSERT OR REPLACE INTO deprecated(operatorbundle_name) SELECT operatorbundle_name FROM properties WHERE properties.type='%s'`, registry.DeprecatedType)
3333
_, err := tx.ExecContext(ctx, initDeprecated)
3434

3535
return err

pkg/sqlite/migrations/012_deprecated_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func TestDeprecated(t *testing.T) {
2626
require.NoError(t, err)
2727
_, err = db.Exec(insertProperty, registry.DeprecatedType, "operator.v1.0.0", "1.0.0", "quay.io/operator:v1.0.0")
2828
require.NoError(t, err)
29+
// Add a duplicate deprecated property to ensure idempotency of the migration
30+
_, err = db.Exec(insertProperty, registry.DeprecatedType, "operator.v1.0.0", "1.0.0", "quay.io/operator:v1.0.0")
31+
require.NoError(t, err)
2932
_, err = db.Exec(insertProperty, "extraneous", "operator.v1.0.0", "1.0.0", "quay.io/operator:v1.0.0")
3033
require.NoError(t, err)
3134

0 commit comments

Comments
 (0)