blob: 760beb22cc7c0c8f325e93705c72f9620c0f798a (
plain)
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
|
package main
import (
"flag"
"os"
"sort"
"github.com/olekukonko/tablewriter"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore"
)
const sqlMigrateStatusCmdName = "sql-migrate-status"
type sqlMigrateStatusSubcommand struct{}
func (s *sqlMigrateStatusSubcommand) FlagSet() *flag.FlagSet {
return flag.NewFlagSet(sqlMigrateStatusCmdName, flag.ExitOnError)
}
func (s *sqlMigrateStatusSubcommand) Exec(flags *flag.FlagSet, conf config.Config) error {
migrations, err := datastore.MigrateStatus(conf)
if err != nil {
return err
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Migration", "Applied"})
table.SetColWidth(60)
// Display the rows in order of name
var keys []string
for k := range migrations {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
m := migrations[k]
applied := "no"
if m.Unknown {
applied = "unknown migration"
} else if m.Migrated {
applied = m.AppliedAt.String()
}
table.Append([]string{
k,
applied,
})
}
table.Render()
return err
}
|