Skip to content

Commit

Permalink
fix: passing the table DB name to the enum-generation steps (gnormal#98)
Browse files Browse the repository at this point in the history
This changes allows to use the table name while generating file names or struct
names (in Go) for enums, which may help avoid name collisions (2 tables might
have 2 different enums but with the same column name).

Also: updated the dependencies with dep ensure.
  • Loading branch information
wuleninja committed Jul 25, 2018
1 parent 1af13f4 commit bb455af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions run/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func makeData(log *log.Logger, info *database.Info, cfg *Config) (*data.DBData,
enum := &data.Enum{
DBName: e.Name,
Schema: sch,
Table: &data.Table{
DBName: e.Table,
},
}
sch.Enums = append(sch.Enums, enum)
enum.Name, err = convert(e.Name)
Expand Down
2 changes: 1 addition & 1 deletion run/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func generateSchemas(env environ.Values, cfg *Config, db *data.DBData) error {
func generateEnums(env environ.Values, cfg *Config, db *data.DBData) error {
for _, schema := range db.Schemas {
for _, enum := range schema.Enums {
fileData := struct{ Schema, Enum string }{Schema: schema.Name, Enum: enum.Name}
fileData := struct{ Schema, Enum, Table string }{Schema: schema.Name, Enum: enum.Name, Table: enum.Table.DBName}
contents := data.EnumData{
Enum: enum,
DB: db,
Expand Down

0 comments on commit bb455af

Please sign in to comment.