fix: Honor Package level renames in v2 yaml config#2001
Merged
kyleconroy merged 1 commit intosqlc-dev:mainfrom Apr 7, 2023
Merged
fix: Honor Package level renames in v2 yaml config#2001kyleconroy merged 1 commit intosqlc-dev:mainfrom
kyleconroy merged 1 commit intosqlc-dev:mainfrom
Conversation
Package level config renames override global level config renames
|
This seems to fix #1977. |
Contributor
Author
|
Is it possible to get this in soon? Seems small and trivial? |
Contributor
|
I noticed the same problem and wrote a patch, but then I found that this PR had already been submitted! 🤣 diff --git a/internal/config/config.go b/internal/config/config.go
index 0dfd57bc..1c8942c8 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -214,12 +214,22 @@ func Combine(conf Config, pkg SQL) CombinedSettings {
Global: conf,
Package: pkg,
}
+ merge := func(dst, src map[string]string) map[string]string {
+ for k, v := range src {
+ if dst == nil {
+ dst = make(map[string]string)
+ }
+ dst[k] = v
+ }
+ return dst
+ }
if conf.Gen.Go != nil {
- cs.Rename = conf.Gen.Go.Rename
+ cs.Rename = merge(cs.Rename, conf.Gen.Go.Rename)
cs.Overrides = append(cs.Overrides, conf.Gen.Go.Overrides...)
}
if pkg.Gen.Go != nil {
cs.Go = *pkg.Gen.Go
+ cs.Rename = merge(cs.Rename, pkg.Gen.Go.Rename)
cs.Overrides = append(cs.Overrides, pkg.Gen.Go.Overrides...)
}
if pkg.Gen.JSON != nil { |
Contributor
|
@kyleconroy There are a workaround with global |
|
@kyleconroy respectful bump to make you aware of this tiny PR fixing #1977 :-) |
Contributor
Author
That is what I did in the meantime. |
alfonsodev
pushed a commit
to ExponentiaTeam/sqlc
that referenced
this pull request
Oct 13, 2025
Package level config renames override global level config renames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When following the docs for renames for
pkgscoped renames, the renames were not applying. This is my first look into the sqlc config, but it looked like things were just not plumbed through.I just adds setting the renames from the yaml parse. In the combine settings I made sure to assign the renames from the pkg (the global was already set). This change does make pkg renames override global ones.
For unit testing, I noticed all the
endtoend/testdatause a v1 config. Instead of adding more vectors to that to also dov2directories, what if we just added asqlc.v1.yamlandsqlc.v2.yamlto each directory and run it twice? Or something of that nature to test v2 configs? At present this is not tested aside from some manual checking.