-
Notifications
You must be signed in to change notification settings - Fork 346
/
migrate.go
54 lines (45 loc) · 1.12 KB
/
migrate.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
package main
import (
"fmt"
"os"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/determined-ai/determined/master/internal/config"
"github.com/determined-ai/determined/master/internal/db"
"github.com/determined-ai/determined/master/pkg/logger"
)
func newMigrateCmd() *cobra.Command {
return &cobra.Command{
Use: "migrate",
Short: "migrate the db",
Run: func(cmd *cobra.Command, args []string) {
if err := runMigrate(cmd, args); err != nil {
log.Error(fmt.Sprintf("%+v", err))
os.Exit(1)
}
},
}
}
func runMigrate(cmd *cobra.Command, args []string) error {
logStore := logger.NewLogBuffer(logStoreSize)
log.AddHook(logStore)
err := initializeConfig()
if err != nil {
return err
}
config := config.GetMasterConfig()
database, err := db.Connect(&config.DB)
if err != nil {
return err
}
defer func() {
if errd := database.Close(); errd != nil {
log.Errorf("error closing pg connection: %s", errd)
}
}()
if err = database.Migrate(config.DB.Migrations, args); err != nil {
return errors.Wrap(err, "running migrations")
}
return nil
}