github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/cmd/mattermost/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/spf13/cobra" 11 ) 12 13 var ResetCmd = &cobra.Command{ 14 Use: "reset", 15 Short: "Reset the database to initial state", 16 Long: "Completely erases the database causing the loss of all data. This will reset Mattermost to its initial state.", 17 RunE: resetCmdF, 18 } 19 20 func init() { 21 ResetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.") 22 23 RootCmd.AddCommand(ResetCmd) 24 } 25 26 func resetCmdF(command *cobra.Command, args []string) error { 27 a, err := InitDBCommandContextCobra(command) 28 if err != nil { 29 return err 30 } 31 defer a.Shutdown() 32 33 confirmFlag, _ := command.Flags().GetBool("confirm") 34 if !confirmFlag { 35 var confirm string 36 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 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 CommandPrettyPrintln("Database successfully reset") 51 52 return nil 53 }