@@ -1369,13 +1369,13 @@ if Code.ensure_loaded?(Tds) do
13691369 quote_name ( name ) ,
13701370 " " ,
13711371 reference_column_type ( ref . type , opts ) ,
1372- column_options ( table , name , opts ) ,
1372+ column_options ( table , name , ref . type , opts ) ,
13731373 reference_expr ( ref , table , name )
13741374 ]
13751375 end
13761376
13771377 defp column_definition ( table , { :add , name , type , opts } ) do
1378- [ quote_name ( name ) , " " , column_type ( type , opts ) , column_options ( table , name , opts ) ]
1378+ [ quote_name ( name ) , " " , column_type ( type , opts ) , column_options ( table , name , type , opts ) ]
13791379 end
13801380
13811381 defp column_changes ( statement , table , columns ) do
@@ -1396,7 +1396,7 @@ if Code.ensure_loaded?(Tds) do
13961396 quote_name ( name ) ,
13971397 " " ,
13981398 reference_column_type ( ref . type , opts ) ,
1399- column_options ( table , name , opts ) ,
1399+ column_options ( table , name , ref . type , opts ) ,
14001400 "; "
14011401 ] ,
14021402 [ statement_prefix , "ADD" , constraint_expr ( ref , table , name ) , "; " ]
@@ -1411,7 +1411,7 @@ if Code.ensure_loaded?(Tds) do
14111411 quote_name ( name ) ,
14121412 " " ,
14131413 column_type ( type , opts ) ,
1414- column_options ( table , name , opts ) ,
1414+ column_options ( table , name , type , opts ) ,
14151415 "; "
14161416 ]
14171417 ]
@@ -1430,7 +1430,7 @@ if Code.ensure_loaded?(Tds) do
14301430 quote_name ( column_name ) ,
14311431 " " ,
14321432 column_type ( type , opts ) ,
1433- column_options ( table , column_name , opts ) ,
1433+ column_options ( table , column_name , type , opts ) ,
14341434 "; "
14351435 ]
14361436 ]
@@ -1446,7 +1446,7 @@ if Code.ensure_loaded?(Tds) do
14461446 quote_name ( name ) ,
14471447 " " ,
14481448 reference_column_type ( ref . type , opts ) ,
1449- column_options ( table , name , opts ) ,
1449+ column_options ( table , name , ref . type , opts ) ,
14501450 "; "
14511451 ] ,
14521452 [ statement_prefix , "ADD" , constraint_expr ( ref , table , name ) , "; " ] ,
@@ -1455,6 +1455,8 @@ if Code.ensure_loaded?(Tds) do
14551455 end
14561456
14571457 defp column_change ( statement_prefix , table , { :modify , name , type , opts } ) do
1458+ collation = Keyword . fetch ( opts , :collation )
1459+
14581460 [
14591461 drop_constraint_from_expr ( opts [ :from ] , table , name , statement_prefix ) ,
14601462 maybe_drop_default_expr ( statement_prefix , table , name , opts ) ,
@@ -1465,6 +1467,7 @@ if Code.ensure_loaded?(Tds) do
14651467 " " ,
14661468 column_type ( type , opts ) ,
14671469 null_expr ( Keyword . get ( opts , :null ) ) ,
1470+ collation_expr ( collation , type ) ,
14681471 "; "
14691472 ] ,
14701473 [ column_default_value ( statement_prefix , table , name , opts ) ]
@@ -1497,10 +1500,14 @@ if Code.ensure_loaded?(Tds) do
14971500 ]
14981501 end
14991502
1500- defp column_options ( table , name , opts ) do
1503+ defp column_options ( table , name , type , opts ) do
15011504 default = Keyword . fetch ( opts , :default )
15021505 null = Keyword . get ( opts , :null )
1503- [ null_expr ( null ) , default_expr ( table , name , default ) ]
1506+
1507+ collation =
1508+ Keyword . fetch ( opts , :collation )
1509+
1510+ [ null_expr ( null ) , default_expr ( table , name , default ) , collation_expr ( collation , type ) ]
15041511 end
15051512
15061513 defp column_default_value ( statement_prefix , table , name , opts ) do
@@ -1516,6 +1523,13 @@ if Code.ensure_loaded?(Tds) do
15161523 defp null_expr ( true ) , do: [ " NULL" ]
15171524 defp null_expr ( _ ) , do: [ ]
15181525
1526+ defp collation_expr ( { :ok , collation_name } , text_type )
1527+ when text_type in ~w/ string char varchar nchar nvarchar text ntext/ a do
1528+ " COLLATE #{ collation_name } "
1529+ end
1530+
1531+ defp collation_expr ( _ , _ ) , do: [ ]
1532+
15191533 defp default_expr ( _table , _name , { :ok , nil } ) ,
15201534 do: [ ]
15211535
0 commit comments