@@ -274,6 +274,27 @@ defmodule Ecto.Migration do
274
274
275
275
config :app, App.Repo, migration_default_prefix: "my_prefix"
276
276
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
+
277
298
## Comments
278
299
279
300
Migrations where you create or alter a table support specifying table
@@ -1166,6 +1187,7 @@ defmodule Ecto.Migration do
1166
1187
specified.
1167
1188
* `:scale` - the scale of a numeric type. Defaults to `0`.
1168
1189
* `:comment` - adds a comment to the added column.
1190
+ * `:collation` - the collation of the text type.
1169
1191
* `:after` - positions field after the specified one. Only supported on MySQL,
1170
1192
it is ignored by other databases.
1171
1193
* `:generated` - a string representing the expression for a generated column. See
@@ -1345,6 +1367,7 @@ defmodule Ecto.Migration do
1345
1367
specified.
1346
1368
* `:scale` - the scale of a numeric type. Defaults to `0`.
1347
1369
* `:comment` - adds a comment to the modified column.
1370
+ * `:collation` - the collation of the text type.
1348
1371
"""
1349
1372
def modify ( column , type , opts \\ [ ] ) when is_atom ( column ) and is_list ( opts ) do
1350
1373
validate_precision_opts! ( opts , column )
0 commit comments