Skip to content

Commit

Permalink
Reorganise SQLite migration sub commands
Browse files Browse the repository at this point in the history
  • Loading branch information
surik committed Sep 28, 2023
1 parent 53276ec commit fead817
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
10 changes: 5 additions & 5 deletions management/cmd/rollback.go → management/cmd/migration_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/spf13/cobra"
)

var shortRollback = "Rollback SQLite store to JSON filestore. Please make a backup of the SQLite file before running this command."
var shortDown = "Rollback SQLite store to JSON filestore. Please make a backup of the SQLite file before running this command."

var rollbackCmd = &cobra.Command{
Use: "rollback [--datadir directory] [--log-file console]",
Short: shortRollback,
Long: shortRollback +
var downCmd = &cobra.Command{
Use: "down [--datadir directory] [--log-file console]",
Short: shortDown,
Long: shortDown +
"\n\n" +
"This command reads the content of {datadir}/store.db and migrates it to {datadir}/store.json that can be used by File store driver.",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
10 changes: 5 additions & 5 deletions management/cmd/migration.go → management/cmd/migration_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/spf13/cobra"
)

var shortMigration = "Migrate JSON file store to SQLite store. Please make a backup of the store json file before running this command."
var shortUp = "Migrate JSON file store to SQLite store. Please make a backup of the JSON file before running this command."

var migrationCmd = &cobra.Command{
Use: "migration [--datadir directory] [--log-file console]",
Short: shortMigration,
Long: shortMigration +
var upCmd = &cobra.Command{
Use: "up [--datadir directory] [--log-file console]",
Short: shortUp,
Long: shortUp +
"\n\n" +
"This command reads the content of {datadir}/store.json and migrates it to {datadir}/store.db that can be used by SQLite store driver.",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
16 changes: 11 additions & 5 deletions management/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ var (
SilenceUsage: true,
}

migrationCmd = &cobra.Command{
Use: "sqlite-migration",
Short: "Contains sub commands to perform filesotre to sqlite store migration and rollback",
Long: "",
SilenceUsage: true,
}
// Execution control channel for stopCh signal
stopCh chan int
)
Expand Down Expand Up @@ -64,13 +70,13 @@ func init() {
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Netbird log path. If console is specified the the log will be output to stdout")
rootCmd.AddCommand(mgmtCmd)

migrationCmd.Flags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location")
migrationCmd.PersistentFlags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location")
migrationCmd.MarkFlagRequired("datadir") //nolint
rootCmd.AddCommand(migrationCmd)

rollbackCmd.Flags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location")
rollbackCmd.MarkFlagRequired("datadir") //nolint
rootCmd.AddCommand(rollbackCmd)
migrationCmd.AddCommand(upCmd)
migrationCmd.AddCommand(downCmd)

rootCmd.AddCommand(migrationCmd)
}

// SetupCloseHandler handles SIGTERM signal and exits with success
Expand Down

0 comments on commit fead817

Please sign in to comment.