diff --git a/tools/goctl/model/cmd.go b/tools/goctl/model/cmd.go index faaf63e6..0528b3b5 100644 --- a/tools/goctl/model/cmd.go +++ b/tools/goctl/model/cmd.go @@ -56,6 +56,7 @@ func init() { pgDatasourceCmdFlags.StringVar(&command.VarStringHome, "home") pgDatasourceCmdFlags.StringVar(&command.VarStringRemote, "remote") 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.BoolVarP(&mongo.VarBoolCache, "cache", "c") diff --git a/tools/goctl/model/sql/command/command.go b/tools/goctl/model/sql/command/command.go index f00b4229..dc2aabc6 100644 --- a/tools/goctl/model/sql/command/command.go +++ b/tools/goctl/model/sql/command/command.go @@ -216,8 +216,9 @@ func PostgreSqlDataSource(_ *cobra.Command, _ []string) error { if err != nil { 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 { @@ -329,7 +330,7 @@ func fromMysqlDataSource(arg dataSourceArg) error { 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) if len(url) == 0 { 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") } - 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 { return err }