-
Notifications
You must be signed in to change notification settings - Fork 239
/
013_rm_truncated_deprecations.go
31 lines (25 loc) · 1.07 KB
/
013_rm_truncated_deprecations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package migrations
import (
"context"
"database/sql"
)
const RmTruncatedDeprecationsMigrationKey = 13
// Register this migration
func init() {
registerMigration(RmTruncatedDeprecationsMigrationKey, rmTruncatedDeprecationsMigration)
}
var rmTruncatedDeprecationsMigration = &Migration{
Id: RmTruncatedDeprecationsMigrationKey,
Up: func(ctx context.Context, tx *sql.Tx) error {
// Delete deprecation history for all bundles that no longer exist in the operatorbundle table
// These bundles have been truncated by more recent deprecations and would only confuse future operations on an index;
// e.g. adding a previously truncated bundle to a package removed via `opm index|registry rm` would lead to that bundle
// being deprecated
_, err := tx.ExecContext(ctx, `DELETE FROM deprecated WHERE deprecated.operatorbundle_name NOT IN (SELECT DISTINCT deprecated.operatorbundle_name FROM (deprecated INNER JOIN operatorbundle ON deprecated.operatorbundle_name = operatorbundle.name))`)
return err
},
Down: func(ctx context.Context, tx *sql.Tx) error {
// No-op
return nil
},
}