From 1ce3244c17539ea8a4d85c4346bf50b9e330af9b Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 15 Jan 2021 10:33:23 +0800 Subject: [PATCH] drop the legacy migration command --- pkg/cmd/migrate.go | 79 -------------------------------------------- pkg/cmd/migration.go | 2 -- 2 files changed, 81 deletions(-) delete mode 100644 pkg/cmd/migrate.go delete mode 100644 pkg/cmd/migration.go diff --git a/pkg/cmd/migrate.go b/pkg/cmd/migrate.go deleted file mode 100644 index 8814c5545..000000000 --- a/pkg/cmd/migrate.go +++ /dev/null @@ -1,79 +0,0 @@ -package cmd - -import ( - "context" - "fmt" - "os" - "os/exec" - "path" - - "github.com/c9s/goose" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "github.com/spf13/viper" - - "github.com/c9s/bbgo/pkg/bbgo" -) - -func init() { - MigrateCmd.Flags().Bool("no-update", false, "update source repository") - RootCmd.AddCommand(MigrateCmd) -} - -var MigrateCmd = &cobra.Command{ - Use: "migrate", - Short: "run database migration", - SilenceUsage: true, - Args: cobra.MinimumNArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - ctx := context.Background() - - noUpdate, err := cmd.Flags().GetBool("no-update") - if err != nil { - return err - } - - mysqlURL := viper.GetString("mysql-url") - mysqlURL = fmt.Sprintf("%s?parseTime=true", mysqlURL) - db, err := goose.OpenDBWithDriver("mysql", mysqlURL) - if err != nil { - return err - } - - dotDir := bbgo.HomeDir() - sourceDir := bbgo.SourceDir() - migrationDir := path.Join(sourceDir, "migrations") - - logrus.Infof("creating dir: %s", dotDir) - if err := os.Mkdir(dotDir, 0777); err != nil { - // return err - } - - logrus.Infof("checking %s", sourceDir) - _, err = os.Stat(sourceDir) - if err != nil { - logrus.Infof("cloning bbgo source into %s ...", sourceDir) - cmd := exec.CommandContext(ctx, "git", "clone", "https://github.com/c9s/bbgo", sourceDir) - if err := cmd.Run(); err != nil { - return err - } - } else if !noUpdate { - logrus.Infof("updating: %s ...", sourceDir) - cmd := exec.CommandContext(ctx, "git", "--work-tree", sourceDir, "pull") - if err := cmd.Run(); err != nil { - return err - } - } - - logrus.Infof("using migration file dir: %s", migrationDir) - - command := args[0] - if err := goose.Run(command, db, migrationDir); err != nil { - logrus.Fatalf("goose run: %v", err) - } - - defer db.Close() - - return nil - }, -} diff --git a/pkg/cmd/migration.go b/pkg/cmd/migration.go deleted file mode 100644 index 89225e6ee..000000000 --- a/pkg/cmd/migration.go +++ /dev/null @@ -1,2 +0,0 @@ -package cmd -