-
Notifications
You must be signed in to change notification settings - Fork 320
Add support in migrations for collations in Postgres #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Yes, a PR is welcome! |
Sorry, to be clear, yes please update this PR :) |
@josevalim I think this PR is ready for review. I did not add tests for modifying the collation on columns that have references to other columns. If you want I can look into that, but it requires some more SQL in between the DDL commands. |
" COLLATE \"#{collation_name}\"" | ||
end | ||
|
||
defp collation_expr(_, _), do: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should either raise or not check the type and let the underlying SQL operation fail. Perhaps the second option is best, because I don’t know if Postgres supports collations for custom types (which would then be impossible to check).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgres does support collations for custom types, so letting the SQL fail is the best option.
lib/ecto/migration.ex
Outdated
are not known by `ecto_sql` and specifying an incorrect collation might cause | ||
a migration to fail. | ||
|
||
### N.B. be sure to match the collation on any columns that reference other text columns. See example below |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s convert this to a regular paragraph or admonition. Please also avoid abbreviations such as NB, i.e. and similar :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
thanks! :) |
I found this was missing when I added fractional indexes in my application. The default en_US-UTF8 collation will sort "Zy" after "a0". After setting the collation on the columns manually to "POSIX" the sorting worked as expected.
If there is interest to pull this into
ecto_sql
I will add documentation and support for MySQL and MSSQL as well.