Browse Source

Support for adding ignore_columns parameters to the goctl model pg (#3427)

cary 1 year ago
parent
commit
81ae7d36b5
2 changed files with 5 additions and 3 deletions
  1. 1 0
      tools/goctl/model/cmd.go
  2. 4 3
      tools/goctl/model/sql/command/command.go

+ 1 - 0
tools/goctl/model/cmd.go

@@ -56,6 +56,7 @@ func init() {
 	pgDatasourceCmdFlags.StringVar(&command.VarStringHome, "home")
 	pgDatasourceCmdFlags.StringVar(&command.VarStringHome, "home")
 	pgDatasourceCmdFlags.StringVar(&command.VarStringRemote, "remote")
 	pgDatasourceCmdFlags.StringVar(&command.VarStringRemote, "remote")
 	pgDatasourceCmdFlags.StringVar(&command.VarStringBranch, "branch")
 	pgDatasourceCmdFlags.StringVar(&command.VarStringBranch, "branch")
+	pgCmd.PersistentFlags().StringSliceVarPWithDefaultValue(&command.VarStringSliceIgnoreColumns, "ignore-columns", "i", []string{"create_at", "created_at", "create_time", "update_at", "updated_at", "update_time"})
 
 
 	mongoCmdFlags.StringSliceVarP(&mongo.VarStringSliceType, "type", "t")
 	mongoCmdFlags.StringSliceVarP(&mongo.VarStringSliceType, "type", "t")
 	mongoCmdFlags.BoolVarP(&mongo.VarBoolCache, "cache", "c")
 	mongoCmdFlags.BoolVarP(&mongo.VarBoolCache, "cache", "c")

+ 4 - 3
tools/goctl/model/sql/command/command.go

@@ -216,8 +216,9 @@ func PostgreSqlDataSource(_ *cobra.Command, _ []string) error {
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
+	ignoreColumns := mergeColumns(VarStringSliceIgnoreColumns)
 
 
-	return fromPostgreSqlDataSource(url, pattern, dir, schema, cfg, cache, idea, VarBoolStrict)
+	return fromPostgreSqlDataSource(url, pattern, dir, schema, cfg, cache, idea, VarBoolStrict, ignoreColumns)
 }
 }
 
 
 type ddlArg struct {
 type ddlArg struct {
@@ -329,7 +330,7 @@ func fromMysqlDataSource(arg dataSourceArg) error {
 	return generator.StartFromInformationSchema(matchTables, arg.cache, arg.strict)
 	return generator.StartFromInformationSchema(matchTables, arg.cache, arg.strict)
 }
 }
 
 
-func fromPostgreSqlDataSource(url, pattern, dir, schema string, cfg *config.Config, cache, idea, strict bool) error {
+func fromPostgreSqlDataSource(url, pattern, dir, schema string, cfg *config.Config, cache, idea, strict bool, ignoreColumns []string) error {
 	log := console.NewConsole(idea)
 	log := console.NewConsole(idea)
 	if len(url) == 0 {
 	if len(url) == 0 {
 		log.Error("%v", "expected data source of postgresql, but nothing found")
 		log.Error("%v", "expected data source of postgresql, but nothing found")
@@ -376,7 +377,7 @@ func fromPostgreSqlDataSource(url, pattern, dir, schema string, cfg *config.Conf
 		return errors.New("no tables matched")
 		return errors.New("no tables matched")
 	}
 	}
 
 
-	generator, err := gen.NewDefaultGenerator(dir, cfg, gen.WithConsoleOption(log), gen.WithPostgreSql())
+	generator, err := gen.NewDefaultGenerator(dir, cfg, gen.WithConsoleOption(log), gen.WithPostgreSql(), gen.WithIgnoreColumns(ignoreColumns))
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}