fix: model path
This commit is contained in:
@@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
"github.com/go-jet/jet/v2/generator/postgres"
|
"github.com/go-jet/jet/v2/generator/postgres"
|
||||||
"github.com/go-jet/jet/v2/generator/template"
|
"github.com/go-jet/jet/v2/generator/template"
|
||||||
pg "github.com/go-jet/jet/v2/postgres"
|
pg "github.com/go-jet/jet/v2/postgres"
|
||||||
|
"github.com/jackc/pgconn"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@@ -66,24 +68,34 @@ func commandGenModelE(cmd *cobra.Command, args []string) error {
|
|||||||
"bool",
|
"bool",
|
||||||
}
|
}
|
||||||
|
|
||||||
return postgres.GenerateDSN(
|
err = postgres.GenerateDSN(
|
||||||
dbConf.DSN(),
|
dbConf.DSN(),
|
||||||
dbConf.Schema,
|
dbConf.Schema,
|
||||||
"database/models",
|
"database",
|
||||||
template.Default(pg.Dialect).
|
template.Default(pg.Dialect).
|
||||||
UseSchema(func(schema metadata.Schema) template.Schema {
|
UseSchema(func(schema metadata.Schema) template.Schema {
|
||||||
return template.
|
return template.
|
||||||
DefaultSchema(schema).
|
DefaultSchema(schema).
|
||||||
UseSQLBuilder(
|
UseSQLBuilder(
|
||||||
template.DefaultSQLBuilder().UseTable(func(table metadata.Table) template.TableSQLBuilder {
|
template.
|
||||||
tbl := template.DefaultTableSQLBuilder(table)
|
DefaultSQLBuilder().
|
||||||
|
UseTable(func(table metadata.Table) template.TableSQLBuilder {
|
||||||
|
tbl := template.DefaultTableSQLBuilder(table)
|
||||||
|
|
||||||
if lo.Contains(conf.Ignores, table.Name) {
|
if lo.Contains(conf.Ignores, table.Name) {
|
||||||
tbl.Skip = true
|
tbl.Skip = true
|
||||||
log.Infof("Skip table %s", table.Name)
|
log.Infof("Skip table %s", table.Name)
|
||||||
}
|
}
|
||||||
return tbl
|
return tbl
|
||||||
}),
|
}).
|
||||||
|
UseEnum(func(meta metadata.Enum) template.EnumSQLBuilder {
|
||||||
|
enum := template.DefaultEnumSQLBuilder(meta)
|
||||||
|
if lo.Contains(conf.Ignores, meta.Name) {
|
||||||
|
enum.Skip = true
|
||||||
|
log.Infof("Skip enum %s", meta.Name)
|
||||||
|
}
|
||||||
|
return enum
|
||||||
|
}),
|
||||||
).
|
).
|
||||||
UseModel(
|
UseModel(
|
||||||
template.
|
template.
|
||||||
@@ -135,4 +147,23 @@ func commandGenModelE(cmd *cobra.Command, args []string) error {
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, err := pgconn.ParseConfig(dbConf.DSN())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.RemoveAll("database/schemas"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dataPath := fmt.Sprintf("database/%s", cfg.Database)
|
||||||
|
if err := os.Rename(dataPath, "database/schemas"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user