Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2020-01-15 00:01:59 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2020-01-15 00:01:59 +0300
commite8d3b93570e541492df616cb277216f5947abaef (patch)
tree8f1317b52568e782a9d46a1e6198471ba12b18a8 /cmd
parent98ed1d2ec19a5229f758ec9817a60b869ad591d9 (diff)
Add sql-migrate subcommand to Praefect
Diffstat (limited to 'cmd')
-rw-r--r--cmd/praefect/main.go23
-rw-r--r--cmd/praefect/subcommand.go51
2 files changed, 51 insertions, 23 deletions
diff --git a/cmd/praefect/main.go b/cmd/praefect/main.go
index 451c56e65..8536cdbbe 100644
--- a/cmd/praefect/main.go
+++ b/cmd/praefect/main.go
@@ -205,26 +205,3 @@ func testSQLConnection(logger *logrus.Entry, conf config.Config) {
logger.Info("SQL connection check successful")
}
}
-
-// subCommand returns an exit code, to be fed into os.Exit.
-func subCommand(conf config.Config, arg0 string, argRest []string) int {
- switch arg0 {
- case "sql-ping":
- return sqlPing(conf)
- default:
- fmt.Printf("%s: unknown subcommand: %q\n", progname, arg0)
- return 1
- }
-}
-
-func sqlPing(conf config.Config) int {
- const subCmd = progname + " sql-ping"
-
- if err := datastore.CheckPostgresVersion(conf); err != nil {
- fmt.Printf("%s: fail: %v\n", subCmd, err)
- return 1
- }
-
- fmt.Printf("%s: OK\n", subCmd)
- return 0
-}
diff --git a/cmd/praefect/subcommand.go b/cmd/praefect/subcommand.go
new file mode 100644
index 000000000..48f5b0387
--- /dev/null
+++ b/cmd/praefect/subcommand.go
@@ -0,0 +1,51 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "gitlab.com/gitlab-org/gitaly/internal/praefect/config"
+ "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore"
+)
+
+// subCommand returns an exit code, to be fed into os.Exit.
+func subCommand(conf config.Config, arg0 string, argRest []string) int {
+ switch arg0 {
+ case "sql-ping":
+ return sqlPing(conf)
+ case "sql-migrate":
+ return sqlMigrate(conf)
+ default:
+ fmt.Printf("%s: unknown subcommand: %q\n", progname, arg0)
+ return 1
+ }
+}
+
+func sqlPing(conf config.Config) int {
+ const subCmd = progname + " sql-ping"
+
+ if err := datastore.CheckPostgresVersion(conf); err != nil {
+ printfErr("%s: fail: %v\n", subCmd, err)
+ return 1
+ }
+
+ fmt.Printf("%s: OK\n", subCmd)
+ return 0
+}
+
+func sqlMigrate(conf config.Config) int {
+ const subCmd = progname + " sql-migrate"
+
+ n, err := datastore.Migrate(conf)
+ if err != nil {
+ printfErr("%s: fail: %v\n", subCmd, err)
+ return 1
+ }
+
+ fmt.Printf("%s: OK (applied %d migrations)\n", subCmd, n)
+ return 0
+}
+
+func printfErr(format string, a ...interface{}) (int, error) {
+ return fmt.Fprintf(os.Stderr, format, a...)
+}