Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ const (
)

type Config struct {
Version string `json:"version" yaml:"version"`
Cloud Cloud `json:"cloud" yaml:"cloud"`
SQL []SQL `json:"sql" yaml:"sql"`
Gen Gen `json:"overrides,omitempty" yaml:"overrides"`
Plugins []Plugin `json:"plugins" yaml:"plugins"`
Rules []Rule `json:"rules" yaml:"rules"`
Version string `json:"version" yaml:"version"`
Cloud Cloud `json:"cloud" yaml:"cloud"`
SQL []SQL `json:"sql" yaml:"sql"`
Overrides Overrides `json:"overrides,omitempty" yaml:"overrides"`
Plugins []Plugin `json:"plugins" yaml:"plugins"`
Rules []Rule `json:"rules" yaml:"rules"`
}

type Database struct {
Expand Down Expand Up @@ -93,11 +93,11 @@ type Rule struct {
Msg string `json:"message" yaml:"message"`
}

type Gen struct {
Go *GenGo `json:"go,omitempty" yaml:"go"`
type Overrides struct {
Go *GoOverrides `json:"go,omitempty" yaml:"go"`
}

type GenGo struct {
type GoOverrides struct {
Overrides []Override `json:"overrides,omitempty" yaml:"overrides"`
Rename map[string]string `json:"rename,omitempty" yaml:"rename"`
}
Expand Down Expand Up @@ -258,11 +258,11 @@ func Combine(conf Config, pkg SQL) CombinedSettings {
Package: pkg,
Rename: map[string]string{},
}
if conf.Gen.Go != nil {
for k, v := range conf.Gen.Go.Rename {
if conf.Overrides.Go != nil {
for k, v := range conf.Overrides.Go.Rename {
cs.Rename[k] = v
}
cs.Overrides = append(cs.Overrides, conf.Gen.Go.Overrides...)
cs.Overrides = append(cs.Overrides, conf.Overrides.Go.Overrides...)
}
if pkg.Gen.Go != nil {
cs.Go = *pkg.Gen.Go
Expand Down
2 changes: 1 addition & 1 deletion internal/config/v_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *V1GenerateSettings) Translate() Config {
}

if len(c.Overrides) > 0 || len(c.Rename) > 0 {
conf.Gen.Go = &GenGo{
conf.Overrides.Go = &GoOverrides{
Overrides: c.Overrides,
Rename: c.Rename,
}
Expand Down
10 changes: 5 additions & 5 deletions internal/config/v_two.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func v2ParseConfig(rd io.Reader) (Config, error) {
if err := conf.validateGlobalOverrides(); err != nil {
return conf, err
}
if conf.Gen.Go != nil {
for i := range conf.Gen.Go.Overrides {
if err := conf.Gen.Go.Overrides[i].Parse(); err != nil {
if conf.Overrides.Go != nil {
for i := range conf.Overrides.Go.Overrides {
if err := conf.Overrides.Go.Overrides[i].Parse(); err != nil {
return conf, err
}
}
Expand Down Expand Up @@ -125,11 +125,11 @@ func (c *Config) validateGlobalOverrides() error {
engines[pkg.Engine] = struct{}{}
}
}
if c.Gen.Go == nil {
if c.Overrides.Go == nil {
return nil
}
usesMultipleEngines := len(engines) > 1
for _, oride := range c.Gen.Go.Overrides {
for _, oride := range c.Overrides.Go.Overrides {
if usesMultipleEngines && oride.Engine == "" {
return fmt.Errorf(`the "engine" field is required for global type overrides because your configuration uses multiple database engines`)
}
Expand Down