github.com/demisto/mattermost-server@v4.9.0-rc3+incompatible/cmd/commands/reset.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package commands 5 6 import ( 7 "errors" 8 "fmt" 9 10 "github.com/mattermost/mattermost-server/cmd" 11 "github.com/spf13/cobra" 12 ) 13 14 var ResetCmd = &cobra.Command{ 15 Use: "reset", 16 Short: "Reset the database to initial state", 17 Long: "Completely erases the database causing the loss of all data. This will reset Mattermost to its initial state.", 18 RunE: resetCmdF, 19 } 20 21 func init() { 22 ResetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.") 23 24 cmd.RootCmd.AddCommand(ResetCmd) 25 } 26 27 func resetCmdF(command *cobra.Command, args []string) error { 28 a, err := cmd.InitDBCommandContextCobra(command) 29 if err != nil { 30 return err 31 } 32 33 confirmFlag, _ := command.Flags().GetBool("confirm") 34 if !confirmFlag { 35 var confirm string 36 cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ") 37 fmt.Scanln(&confirm) 38 39 if confirm != "YES" { 40 return errors.New("ABORTED: You did not answer YES exactly, in all capitals.") 41 } 42 cmd.CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ") 43 fmt.Scanln(&confirm) 44 if confirm != "YES" { 45 return errors.New("ABORTED: You did not answer YES exactly, in all capitals.") 46 } 47 } 48 49 a.Srv.Store.DropAllTables() 50 cmd.CommandPrettyPrintln("Database successfully reset") 51 52 return nil 53 }