@@ -274,6 +274,27 @@ defmodule Ecto.Migration do
274274
275275 config :app, App.Repo, migration_default_prefix: "my_prefix"
276276
277+ ## Collations
278+
279+ For columns with a text type, the collation can be set on the column with the
280+ option `:collation`. This can be useful when relying on ASCII sorting of
281+ characters when using a fractional index for example. All supported collations
282+ are not known by `ecto_sql` and specifying an incorrect collation might cause
283+ a migration to fail.
284+
285+ ### N.B. be sure to match the collation on any columns that reference other text columns. See example below
286+
287+ def change do
288+ create table(:collate_reference) do
289+ add :name, :string, collation: "POSIX"
290+ end
291+
292+ create table(:collate) do
293+ add :string, :string, collation: "POSIX"
294+ add :name_ref, references(:collate_reference, type: :string, column: :name), collation: "POSIX"
295+ end
296+ end
297+
277298 ## Comments
278299
279300 Migrations where you create or alter a table support specifying table
@@ -1166,6 +1187,7 @@ defmodule Ecto.Migration do
11661187 specified.
11671188 * `:scale` - the scale of a numeric type. Defaults to `0`.
11681189 * `:comment` - adds a comment to the added column.
1190+ * `:collation` - the collation of the text type.
11691191 * `:after` - positions field after the specified one. Only supported on MySQL,
11701192 it is ignored by other databases.
11711193 * `:generated` - a string representing the expression for a generated column. See
@@ -1345,6 +1367,7 @@ defmodule Ecto.Migration do
13451367 specified.
13461368 * `:scale` - the scale of a numeric type. Defaults to `0`.
13471369 * `:comment` - adds a comment to the modified column.
1370+ * `:collation` - the collation of the text type.
13481371 """
13491372 def modify ( column , type , opts \\ [ ] ) when is_atom ( column ) and is_list ( opts ) do
13501373 validate_precision_opts! ( opts , column )
0 commit comments