@@ -1552,14 +1552,17 @@ if Code.ensure_loaded?(Postgrex) do
15521552 drop_reference_expr = drop_reference_expr ( opts [ :from ] , table , name )
15531553 prefix_with_comma = ( drop_reference_expr != [ ] && ", " ) || ""
15541554
1555+ common_suffix = [
1556+ reference_expr ( ref , table , name ) ,
1557+ modify_null ( name , opts ) ,
1558+ modify_default ( name , ref . type , opts )
1559+ ]
1560+
15551561 if reference_column_type == column_type ( from_column_type , opts ) do
15561562 [
15571563 drop_reference_expr ,
15581564 prefix_with_comma ,
1559- "ADD " ,
1560- reference_expr ( ref , table , name ) ,
1561- modify_null ( name , opts ) ,
1562- modify_default ( name , ref . type , opts )
1565+ "ADD " | common_suffix
15631566 ]
15641567 else
15651568 [
@@ -1569,10 +1572,7 @@ if Code.ensure_loaded?(Postgrex) do
15691572 quote_name ( name ) ,
15701573 " TYPE " ,
15711574 reference_column_type ,
1572- ", ADD " ,
1573- reference_expr ( ref , table , name ) ,
1574- modify_null ( name , opts ) ,
1575- modify_default ( name , ref . type , opts )
1575+ ", ADD " | common_suffix
15761576 ]
15771577 end
15781578 end
@@ -1588,15 +1588,14 @@ if Code.ensure_loaded?(Postgrex) do
15881588 modify_null = modify_null ( name , Keyword . put ( opts , :prefix_with_comma , any_drop_ref? ) )
15891589 any_modify_null? = modify_null != [ ]
15901590
1591- [
1592- drop_reference_expr ,
1593- modify_null ,
1591+ modify_default =
15941592 modify_default (
15951593 name ,
15961594 type ,
15971595 Keyword . put ( opts , :prefix_with_comma , any_drop_ref? or any_modify_null? )
15981596 )
1599- ]
1597+
1598+ [ drop_reference_expr , modify_null , modify_default ]
16001599 else
16011600 [
16021601 drop_reference_expr ,
0 commit comments