-
Notifications
You must be signed in to change notification settings - Fork 239
/
012_deprecated.go
42 lines (34 loc) · 1.14 KB
/
012_deprecated.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
32
33
34
35
36
37
38
39
40
41
42
package migrations
import (
"context"
"database/sql"
"fmt"
"github.com/operator-framework/operator-registry/pkg/registry"
)
const DeprecatedMigrationKey = 12
// Register this migration
func init() {
registerMigration(DeprecatedMigrationKey, deprecatedMigration)
}
var deprecatedMigration = &Migration{
Id: DeprecatedMigrationKey,
Up: func(ctx context.Context, tx *sql.Tx) error {
// Purposefully forego a foreign key constraint so this table can survive operations that drop bundles and properties
// e.g. a lossy implementation of --overwrite-latest that relies on readding all bundles in a package
sql := `
CREATE TABLE IF NOT EXISTS deprecated (
operatorbundle_name TEXT PRIMARY KEY
);
`
if _, err := tx.ExecContext(ctx, sql); err != nil {
return err
}
initDeprecated := fmt.Sprintf(`INSERT OR REPLACE INTO deprecated(operatorbundle_name) SELECT operatorbundle_name FROM properties WHERE properties.type='%s'`, registry.DeprecatedType)
_, err := tx.ExecContext(ctx, initDeprecated)
return err
},
Down: func(ctx context.Context, tx *sql.Tx) error {
_, err := tx.ExecContext(ctx, `DROP TABLE deprecated`)
return err
},
}