Skip to content

Commit

Permalink
MM-41184: Throw a warning if config migrate wasn't run in local mode (m…
Browse files Browse the repository at this point in the history
…attermost#435)

Also added a note in the docs.

Co-authored-by: Mattermod <[email protected]>
  • Loading branch information
agnivade and mattermod authored Feb 3, 2022
1 parent 629bf95 commit 7bbfdf3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
9 changes: 7 additions & 2 deletions commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var ConfigReloadCmd = &cobra.Command{
var ConfigMigrateCmd = &cobra.Command{
Use: "migrate [from_config] [to_config]",
Short: "Migrate existing config between backends",
Long: "Migrate a file-based configuration to (or from) a database-based configuration. Point the Mattermost server at the target configuration to start using it",
Long: "Migrate a file-based configuration to (or from) a database-based configuration. Point the Mattermost server at the target configuration to start using it. Note that this command is only available in `--local` mode.",
Example: `config migrate path/to/config.json "postgres://mmuser:mostest@localhost:5432/mattermost_test?sslmode=disable&connect_timeout=10"`,
Args: cobra.ExactArgs(2),
RunE: withClient(configMigrateCmdF),
Expand Down Expand Up @@ -499,7 +499,12 @@ func configReloadCmdF(c client.Client, _ *cobra.Command, _ []string) error {
return nil
}

func configMigrateCmdF(c client.Client, _ *cobra.Command, args []string) error {
func configMigrateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
isLocal, _ := cmd.Flags().GetBool("local")
if !isLocal {
return errors.New("this command is only available in local mode. Please set the --local flag")
}

_, err := c.MigrateConfig(args[0], args[1])
if err != nil {
return err
Expand Down
18 changes: 16 additions & 2 deletions commands/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,14 @@ func (s *MmctlUnitTestSuite) TestConfigReloadCmd() {
}

func (s *MmctlUnitTestSuite) TestConfigMigrateCmd() {
s.Run("Should fail without the --local flag", func() {
printer.Clean()
args := []string{"from", "to"}

err := configMigrateCmdF(s.client, &cobra.Command{}, args)
s.Require().Error(err)
})

s.Run("Should be able to migrate config", func() {
printer.Clean()
args := []string{"from", "to"}
Expand All @@ -767,7 +775,10 @@ func (s *MmctlUnitTestSuite) TestConfigMigrateCmd() {
Return(&model.Response{StatusCode: http.StatusOK}, nil).
Times(1)

err := configMigrateCmdF(s.client, &cobra.Command{}, args)
cmd := &cobra.Command{}
cmd.Flags().Bool("local", true, "")

err := configMigrateCmdF(s.client, cmd, args)
s.Require().Nil(err)
s.Len(printer.GetErrorLines(), 0)
})
Expand All @@ -782,7 +793,10 @@ func (s *MmctlUnitTestSuite) TestConfigMigrateCmd() {
Return(&model.Response{StatusCode: http.StatusBadRequest}, errors.New("some-error")).
Times(1)

err := configMigrateCmdF(s.client, &cobra.Command{}, args)
cmd := &cobra.Command{}
cmd.Flags().Bool("local", true, "")

err := configMigrateCmdF(s.client, cmd, args)
s.Require().NotNil(err)
})
}
2 changes: 1 addition & 1 deletion docs/mmctl_config_migrate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Synopsis
~~~~~~~~


Migrate a file-based configuration to (or from) a database-based configuration. Point the Mattermost server at the target configuration to start using it
Migrate a file-based configuration to (or from) a database-based configuration. Point the Mattermost server at the target configuration to start using it. Note that this command is only available in `--local` mode.

::

Expand Down

0 comments on commit 7bbfdf3

Please sign in to comment.