refactor: replace table column name limitations by quoting#5
Merged
Conversation
… queries to prevent sql injection
|
jconzatti
approved these changes
Jan 28, 2026
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
My intention was to, initially, remove the regular expression validations being done to TableName and ColumnName because it limits users, and changing the implied limitation by another reasoning: users should be responsible for the names provided to tables and columns (in other words, it doesn't sound like a real problem that we need to prevent).
TableNameorColumnNamewas being created, users had to check for a potential error returned and handle it, which increases the amount of code written in migrationsSQLBuildersql.DBobject directly carelessly, and I believe there is absolutely nothing we can do against it, since it's a responsibility on their endstructfunction to use pointer receivers instead of value receivers, avoiding issues like accidentally mutating a copy instead of the original structAddColumnsfunction of theschema.TableDescription
This pull request refactors the SQL builder and database APIs to simplify type usage and improve identifier quoting. It updates method signatures to use plain strings instead of wrapper types for table and column names, introduces a quoting mechanism for SQL identifiers, and adjusts usages throughout the codebase and documentation. The changes also update tests and documentation to reflect these API improvements.
API Simplification and Consistency
DropTable,AlterTableAddColumn,AlterTableDropColumn) to use plainstringtypes for table and column names instead of custom wrapper types, simplifying usage across the codebase. [1] [2]Databasestruct and related methods to use a pointer toDBSchema(*schema.DBSchema) and removed the redundantexecutorfield, streamlining database schema access. [1] [2] [3] [4]Identifier Quoting and SQLBuilder Interface
QuoteIdentifiermethod to theSQLBuilderinterface and implemented it for PostgreSQL, ensuring all table and column names are properly quoted in generated SQL to prevent naming conflicts and syntax errors. [1] [2] [3] [4]Documentation and Test Updates
README.mdto use the new API signatures and patterns, making them clearer and more consistent for users. [1] [2] [3]Minor Improvements
ColumnsValuesto use pointer receivers, aligning with Go best practices and ensuring consistency. [1] [2]