github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+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 defer a.Shutdown() 33 34 confirmFlag, _ := command.Flags().GetBool("confirm") 35 if !confirmFlag { 36 var confirm string 37 cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ") 38 fmt.Scanln(&confirm) 39 40 if confirm != "YES" { 41 return errors.New("ABORTED: You did not answer YES exactly, in all capitals.") 42 } 43 cmd.CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ") 44 fmt.Scanln(&confirm) 45 if confirm != "YES" { 46 return errors.New("ABORTED: You did not answer YES exactly, in all capitals.") 47 } 48 } 49 50 a.Srv.Store.DropAllTables() 51 cmd.CommandPrettyPrintln("Database successfully reset") 52 53 return nil 54 }