From 39b8ef623844092671ee73f194968ad26a6d0a6b Mon Sep 17 00:00:00 2001 From: yflau <5521134@qq.com> Date: Thu, 13 Jun 2024 20:00:56 +0800 Subject: [PATCH] add migrate options support for restore cmd --- cmd/restore.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/restore.go b/cmd/restore.go index 56592dca..d5776111 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -21,6 +21,7 @@ import ( ) var restoreForce bool = false +var migrateNoInsert bool = false var restoreCmd = &cobra.Command{ Use: "restore", Short: L("Restore the application data"), @@ -66,7 +67,9 @@ var restoreCmd = &cobra.Command{ } // Restore models - restoreModels(filepath.Join(dst, "model")) + restoreModels(filepath.Join(dst, "model"), []model.MigrateOption{ + model.WithDonotInsertValues(migrateNoInsert), + }) // Restore Data restoreData(filepath.Join(dst, "data")) @@ -80,6 +83,7 @@ var restoreCmd = &cobra.Command{ func init() { restoreCmd.PersistentFlags().BoolVarP(&restoreForce, "force", "", false, L("Force restore")) + restoreCmd.PersistentFlags().BoolVarP(&migrateNoInsert, "migrate-no-insert", "", false, L("Do not insert values when migrating")) } func restoreData(basePath string) { @@ -104,7 +108,7 @@ func restoreData(basePath string) { } } -func restoreModels(basePath string) { +func restoreModels(basePath string, migOpts []model.MigrateOption) { files, err := ioutil.ReadDir(basePath) if err != nil { @@ -116,7 +120,7 @@ func restoreModels(basePath string) { for _, mod := range model.Models { fmt.Printf("\r%s", strings.Repeat(" ", 80)) fmt.Printf(color.GreenString(L("\rUpdate schema model: %s (%s) "), mod.Name, mod.MetaData.Table.Name)) - err := mod.Migrate(true) + err := mod.Migrate(true, migOpts...) if err != nil { fmt.Println(color.RedString(L("Fatal: %s"), err.Error())) os.Exit(1)