@@ -1369,13 +1369,13 @@ if Code.ensure_loaded?(Tds) do
1369
1369
quote_name ( name ) ,
1370
1370
" " ,
1371
1371
reference_column_type ( ref . type , opts ) ,
1372
- column_options ( table , name , opts ) ,
1372
+ column_options ( table , name , ref . type , opts ) ,
1373
1373
reference_expr ( ref , table , name )
1374
1374
]
1375
1375
end
1376
1376
1377
1377
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 ) ]
1379
1379
end
1380
1380
1381
1381
defp column_changes ( statement , table , columns ) do
@@ -1396,7 +1396,7 @@ if Code.ensure_loaded?(Tds) do
1396
1396
quote_name ( name ) ,
1397
1397
" " ,
1398
1398
reference_column_type ( ref . type , opts ) ,
1399
- column_options ( table , name , opts ) ,
1399
+ column_options ( table , name , ref . type , opts ) ,
1400
1400
"; "
1401
1401
] ,
1402
1402
[ statement_prefix , "ADD" , constraint_expr ( ref , table , name ) , "; " ]
@@ -1411,7 +1411,7 @@ if Code.ensure_loaded?(Tds) do
1411
1411
quote_name ( name ) ,
1412
1412
" " ,
1413
1413
column_type ( type , opts ) ,
1414
- column_options ( table , name , opts ) ,
1414
+ column_options ( table , name , type , opts ) ,
1415
1415
"; "
1416
1416
]
1417
1417
]
@@ -1430,7 +1430,7 @@ if Code.ensure_loaded?(Tds) do
1430
1430
quote_name ( column_name ) ,
1431
1431
" " ,
1432
1432
column_type ( type , opts ) ,
1433
- column_options ( table , column_name , opts ) ,
1433
+ column_options ( table , column_name , type , opts ) ,
1434
1434
"; "
1435
1435
]
1436
1436
]
@@ -1446,7 +1446,7 @@ if Code.ensure_loaded?(Tds) do
1446
1446
quote_name ( name ) ,
1447
1447
" " ,
1448
1448
reference_column_type ( ref . type , opts ) ,
1449
- column_options ( table , name , opts ) ,
1449
+ column_options ( table , name , ref . type , opts ) ,
1450
1450
"; "
1451
1451
] ,
1452
1452
[ statement_prefix , "ADD" , constraint_expr ( ref , table , name ) , "; " ] ,
@@ -1455,6 +1455,8 @@ if Code.ensure_loaded?(Tds) do
1455
1455
end
1456
1456
1457
1457
defp column_change ( statement_prefix , table , { :modify , name , type , opts } ) do
1458
+ collation = Keyword . fetch ( opts , :collation )
1459
+
1458
1460
[
1459
1461
drop_constraint_from_expr ( opts [ :from ] , table , name , statement_prefix ) ,
1460
1462
maybe_drop_default_expr ( statement_prefix , table , name , opts ) ,
@@ -1465,6 +1467,7 @@ if Code.ensure_loaded?(Tds) do
1465
1467
" " ,
1466
1468
column_type ( type , opts ) ,
1467
1469
null_expr ( Keyword . get ( opts , :null ) ) ,
1470
+ collation_expr ( collation , type ) ,
1468
1471
"; "
1469
1472
] ,
1470
1473
[ column_default_value ( statement_prefix , table , name , opts ) ]
@@ -1497,10 +1500,14 @@ if Code.ensure_loaded?(Tds) do
1497
1500
]
1498
1501
end
1499
1502
1500
- defp column_options ( table , name , opts ) do
1503
+ defp column_options ( table , name , type , opts ) do
1501
1504
default = Keyword . fetch ( opts , :default )
1502
1505
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 ) ]
1504
1511
end
1505
1512
1506
1513
defp column_default_value ( statement_prefix , table , name , opts ) do
@@ -1516,6 +1523,13 @@ if Code.ensure_loaded?(Tds) do
1516
1523
defp null_expr ( true ) , do: [ " NULL" ]
1517
1524
defp null_expr ( _ ) , do: [ ]
1518
1525
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
+
1519
1533
defp default_expr ( _table , _name , { :ok , nil } ) ,
1520
1534
do: [ ]
1521
1535
0 commit comments