@@ -15,6 +15,37 @@ defmodule Ecto.Integration.MigrationsTest do
1515 end
1616 end
1717
18+ collation = "Latin1_General_CS_AS"
19+ @ collation collation
20+
21+ defmodule CollateMigration do
22+ use Ecto.Migration
23+ @ collation collation
24+
25+ def change do
26+ create table ( :collate_reference ) do
27+ add :name , :string , collation: @ collation
28+ end
29+
30+ create unique_index ( :collate_reference , :name )
31+
32+ create table ( :collate ) do
33+ add :string , :string , collation: @ collation
34+ add :char , :char , size: 255 , collation: @ collation
35+ add :nchar , :nchar , size: 255 , collation: @ collation
36+ add :varchar , :varchar , size: 255 , collation: @ collation
37+ add :nvarchar , :nvarchar , size: 255 , collation: @ collation
38+ add :text , :text , collation: @ collation
39+ add :ntext , :ntext , collation: @ collation
40+ add :name_string , references ( :collate_reference , type: :string , column: :name ) , collation: @ collation
41+ end
42+
43+ alter table ( :collate ) do
44+ modify :string , :string , collation: "Japanese_Bushu_Kakusu_100_CS_AS_KS_WS"
45+ end
46+ end
47+ end
48+
1849 describe "Migrator" do
1950 @ get_lock_command ~s( sp_getapplock @Resource = 'ecto_Ecto.Integration.PoolRepo', @LockMode = 'Exclusive', @LockOwner = 'Transaction', @LockTimeout = -1)
2051 @ create_table_sql ~s( CREATE TABLE [log_mode_table])
@@ -77,5 +108,27 @@ defmodule Ecto.Integration.MigrationsTest do
77108 refute down_log =~ @ version_delete
78109 refute down_log =~ "commit []"
79110 end
111+
112+ test "collation can be set on a column" do
113+ num = @ base_migration + System . unique_integer ( [ :positive ] )
114+ assert :ok = Ecto.Migrator . up ( PoolRepo , num , CollateMigration , log: :info )
115+
116+ query = fn column -> """
117+ SELECT collation_name
118+ FROM information_schema.columns
119+ WHERE table_name = 'collate' AND column_name = '#{ column } ';
120+ """
121+ end
122+
123+ assert % {
124+ rows: [ [ "Japanese_Bushu_Kakusu_100_CS_AS_KS_WS" ] ]
125+ } = Ecto.Adapters.SQL . query! ( PoolRepo , query . ( "string" ) , [ ] )
126+
127+ for type <- ~w/ char varchar nchar nvarchar text ntext/ do
128+ assert % {
129+ rows: [ [ @ collation ] ]
130+ } = Ecto.Adapters.SQL . query! ( PoolRepo , query . ( type ) , [ ] )
131+ end
132+ end
80133 end
81134end
0 commit comments