-
Notifications
You must be signed in to change notification settings - Fork 43
/
1502289152_increase_rootfs_column.go
77 lines (60 loc) · 1.93 KB
/
1502289152_increase_rootfs_column.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package migrations
import (
"database/sql"
"code.cloudfoundry.org/bbs/encryption"
"code.cloudfoundry.org/bbs/format"
"code.cloudfoundry.org/bbs/migration"
"code.cloudfoundry.org/clock"
"code.cloudfoundry.org/lager"
)
func init() {
appendMigration(NewIncreaseRootFSColumnSize())
}
type IncreaseRootFSColumnsSize struct {
serializer format.Serializer
clock clock.Clock
rawSQLDB *sql.DB
dbFlavor string
}
func NewIncreaseRootFSColumnSize() migration.Migration {
return new(IncreaseRootFSColumnsSize)
}
func (e *IncreaseRootFSColumnsSize) String() string {
return migrationString(e)
}
func (e *IncreaseRootFSColumnsSize) Version() int64 {
return 1502289152
}
func (e *IncreaseRootFSColumnsSize) SetCryptor(cryptor encryption.Cryptor) {
e.serializer = format.NewSerializer(cryptor)
}
func (e *IncreaseRootFSColumnsSize) SetRawSQLDB(db *sql.DB) {
e.rawSQLDB = db
}
func (e *IncreaseRootFSColumnsSize) SetClock(c clock.Clock) { e.clock = c }
func (e *IncreaseRootFSColumnsSize) SetDBFlavor(flavor string) { e.dbFlavor = flavor }
func (e *IncreaseRootFSColumnsSize) Up(logger lager.Logger) error {
logger = logger.Session("increase-rootfs-column")
logger.Info("starting")
defer logger.Info("completed")
return e.alterTables(logger, e.rawSQLDB, e.dbFlavor)
}
func (e *IncreaseRootFSColumnsSize) alterTables(logger lager.Logger, db *sql.DB, flavor string) error {
var alterActualLRPsSQL string
if e.dbFlavor == "mysql" {
alterActualLRPsSQL = `ALTER TABLE desired_lrps
MODIFY rootfs VARCHAR(1024) NOT NULL DEFAULT ''`
} else {
alterActualLRPsSQL = `ALTER TABLE desired_lrps
ALTER rootfs TYPE VARCHAR(1024)`
}
logger.Info("altering-tables")
logger.Info("altering the table", lager.Data{"query": alterActualLRPsSQL})
_, err := db.Exec(alterActualLRPsSQL)
if err != nil {
logger.Error("failed-altering-tables", err)
return err
}
logger.Info("altered the table", lager.Data{"query": alterActualLRPsSQL})
return nil
}