mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-07 15:10:01 +08:00
fix: pg gen model missing cache prefix (#4788)
Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
@@ -204,7 +204,6 @@ func PostgreSqlDataSource(_ *cobra.Command, _ []string) error {
|
||||
home := VarStringHome
|
||||
remote := VarStringRemote
|
||||
branch := VarStringBranch
|
||||
prefix := VarStringCachePrefix
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
@@ -226,7 +225,20 @@ func PostgreSqlDataSource(_ *cobra.Command, _ []string) error {
|
||||
}
|
||||
ignoreColumns := mergeColumns(VarStringSliceIgnoreColumns)
|
||||
|
||||
return fromPostgreSqlDataSource(url, patterns, dir, schema, prefix, cfg, cache, idea, VarBoolStrict, ignoreColumns)
|
||||
arg := pgDataSourceArg{
|
||||
url: url,
|
||||
dir: dir,
|
||||
tablePat: patterns,
|
||||
schema: schema,
|
||||
cfg: cfg,
|
||||
cache: cache,
|
||||
idea: idea,
|
||||
strict: VarBoolStrict,
|
||||
ignoreColumns: ignoreColumns,
|
||||
prefix: VarStringCachePrefix,
|
||||
}
|
||||
|
||||
return fromPostgreSqlDataSource(arg)
|
||||
}
|
||||
|
||||
type ddlArg struct {
|
||||
@@ -340,32 +352,43 @@ func fromMysqlDataSource(arg dataSourceArg) error {
|
||||
return generator.StartFromInformationSchema(matchTables, arg.cache, arg.strict)
|
||||
}
|
||||
|
||||
func fromPostgreSqlDataSource(url string, pattern pattern, dir, schema string, prefix string, cfg *config.Config, cache, idea, strict bool, ignoreColumns []string) error {
|
||||
log := console.NewConsole(idea)
|
||||
if len(url) == 0 {
|
||||
type pgDataSourceArg struct {
|
||||
url, dir string
|
||||
tablePat pattern
|
||||
schema string
|
||||
cfg *config.Config
|
||||
cache, idea bool
|
||||
strict bool
|
||||
ignoreColumns []string
|
||||
prefix string
|
||||
}
|
||||
|
||||
func fromPostgreSqlDataSource(arg pgDataSourceArg) error {
|
||||
log := console.NewConsole(arg.idea)
|
||||
if len(arg.url) == 0 {
|
||||
log.Error("%v", "expected data source of postgresql, but nothing found")
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(pattern) == 0 {
|
||||
if len(arg.tablePat) == 0 {
|
||||
log.Error("%v", "expected table or table globbing patterns, but nothing found")
|
||||
return nil
|
||||
}
|
||||
db := postgres.New(url)
|
||||
db := postgres.New(arg.url)
|
||||
im := model.NewPostgreSqlModel(db)
|
||||
|
||||
tables, err := im.GetAllTables(schema)
|
||||
tables, err := im.GetAllTables(arg.schema)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
matchTables := make(map[string]*model.Table)
|
||||
for _, item := range tables {
|
||||
if !pattern.Match(item) {
|
||||
if !arg.tablePat.Match(item) {
|
||||
continue
|
||||
}
|
||||
|
||||
columnData, err := im.FindColumns(schema, item)
|
||||
columnData, err := im.FindColumns(arg.schema, item)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -382,10 +405,11 @@ func fromPostgreSqlDataSource(url string, pattern pattern, dir, schema string, p
|
||||
return errors.New("no tables matched")
|
||||
}
|
||||
|
||||
generator, err := gen.NewDefaultGenerator(prefix, dir, cfg, gen.WithConsoleOption(log), gen.WithPostgreSql(), gen.WithIgnoreColumns(ignoreColumns))
|
||||
generator, err := gen.NewDefaultGenerator(arg.prefix, arg.dir, arg.cfg, gen.WithConsoleOption(log),
|
||||
gen.WithPostgreSql(), gen.WithIgnoreColumns(arg.ignoreColumns))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return generator.StartFromInformationSchema(matchTables, cache, strict)
|
||||
return generator.StartFromInformationSchema(matchTables, arg.cache, arg.strict)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user