Repository navigation
fix(boilingcore): disambiguate identifiers on table slice name collisions - #1483
Open
AdamMagued wants to merge 1 commit into
Open
AdamMagued wants to merge 1 commit into
AdamMagued wants to merge 1 commit into
Conversation
…ions Resolve name collisions occurring during model generation when table singular and plural identifiers coincide (e.g. personas, series, data), or when a table name conflicts with another table's slice type or built-in generator tokens. Specifically: - Register default inflection rule for 'personas' to singularize as 'persona'. - Fall back to suffix disambiguation or append record/query tokens when singular and plural forms match or collide with built-in generator symbols. - Disambiguate table struct names that coincide with another table's slice type. - Add regression unit tests for colliding table names and schema aliases. - Guard driver integration tests with executable path checks when external database clients are unavailable.
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.
Summary
Addresses #1482 where specific database table names (such as
personas,series,data) cause SQLBoiler to generate identical identifiers for both the record struct (type <UpSingular> struct) and the query builder constructor function (func <UpPlural>(...)), resulting in Go compilation errors due to duplicate declarations in package scope.Additionally addresses collisions when table names conflict with built-in generator tokens (
TableNames,ViewNames,NewQuery,M,ErrSyncFail) or with slice types generated for other tables in the schema (<Table>Slice).Root Cause
strmangle, the default inflection ruleset includesrs.AddSingular("as", "as")to preserve terms such asaliasorcanvas. Because of this rule,strmangle.Singular("personas")resolves to"personas"instead of"persona". Consequently, bothUpSingularandUpPluralevaluate to"Personas".UpSingular == UpPlural, SQLBoiler generatestype Personas structin00_struct.go.tplandfunc Personas(...)in13_all.go.tpl, colliding in the generated package.table_namesproducingTableNames, ormproducingM) collide with declarations inboil_table_names.goandboil_types.go.user_sliceyieldingUserSlicealongside ausertable producingtype UserSlice []*User) result in duplicate type declarations.Changes
personas -> personainboilingcore/aliases.gowithininitDefaultInflections().FillAliases:table.UpSingular == table.UpPlural, strip the trailing plural suffixsif applicable, or append descriptive tokens (Records/Record) to differentiate query helpers from record structs.TableNames,ViewNames,NewQuery,M,ErrSyncFail) and appendQueryorRecordsuffixes.<UpSingular>Slice).TestAliasesCollisionsverifying aliases forpersonas,series,data,table_names,m, and table slice interactions.TestNewWithCollidingTableNamesconfirming that code generated for tablepersonascompiles without error.mssql,mysql,psql,sqlite3) to skip when database CLI clients are missing in local test runners.Verification
go test ./... -vandgo vet ./...executed cleanly in isolated Linux sandbox.TestAliasesCollisionspasses with verified singular/plural distinction.personascompiles cleanly undergo build.