Add db_collation argument for fields - #2266
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
Lets a field emit a COLLATE clause in the generated schema, so you can ask for something like NOCASE on SQLite without dropping to raw SQL. Defaults to no collation, so existing schemas are unchanged. Closes tortoise#686
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.
Description
Adds a
db_collationargument to fields so you can set a column collation without hand writing SQL. When it is set, the generated schema gets aCOLLATEclause, and it defaults toNoneso nothing changes for existing models.The example from the issue works now:
produces
"name" VARCHAR(50) COLLATE NOCASE NOT NULLon SQLite. The collation name is passed through as given so you use whatever the target database knows. Postgres wraps it in double quotes since its collation names are identifiers, the other backends emit it as a bare name.Motivation and Context
Closes #686. There was no way to ask a text column for a specific collation (like
NOCASEon SQLite), you had to drop down to raw SQL. This lets you declare it on the field where it belongs.How Has This Been Tested?
Added
test_schema_db_collationthat generates the schema for a model usingdb_collationon aCharFieldand aTextFieldand checks theCOLLATEclause shows up. Ran the sqlite test suite locally and everything passes.Checklist: