@@ -3199,25 +3199,7 @@ defmodule AshPostgres.MigrationGenerator do
3199
3199
end
3200
3200
3201
3201
{ type , size , precision , scale } =
3202
- case type do
3203
- { :varchar , size } ->
3204
- { :varchar , size , nil , nil }
3205
-
3206
- { :binary , size } ->
3207
- { :binary , size , nil , nil }
3208
-
3209
- { :decimal , precision , scale } ->
3210
- { :decimal , nil , precision , scale }
3211
-
3212
- { :decimal , precision } ->
3213
- { :decimal , nil , precision , nil }
3214
-
3215
- { other , size } when is_atom ( other ) and is_integer ( size ) ->
3216
- { other , size , nil , nil }
3217
-
3218
- other ->
3219
- { other , nil , nil , nil }
3220
- end
3202
+ migration_type_to_type ( type )
3221
3203
3222
3204
attribute
3223
3205
|> Map . put ( :default , default )
@@ -3247,6 +3229,32 @@ defmodule AshPostgres.MigrationGenerator do
3247
3229
end )
3248
3230
end
3249
3231
3232
+ defp migration_type_to_type ( type ) do
3233
+ case type do
3234
+ { :varchar , size } ->
3235
+ { :varchar , size , nil , nil }
3236
+
3237
+ { :binary , size } ->
3238
+ { :binary , size , nil , nil }
3239
+
3240
+ { :decimal , precision , scale } ->
3241
+ { :decimal , nil , precision , scale }
3242
+
3243
+ { :decimal , precision } ->
3244
+ { :decimal , nil , precision , nil }
3245
+
3246
+ { other , size } when is_atom ( other ) and is_integer ( size ) ->
3247
+ { other , size , nil , nil }
3248
+
3249
+ { :array , other } ->
3250
+ { nested , size , precision , scale } = migration_type_to_type ( other )
3251
+ { { :array , nested } , size , precision , scale }
3252
+
3253
+ other ->
3254
+ { other , nil , nil , nil }
3255
+ end
3256
+ end
3257
+
3250
3258
defp find_reference ( resource , table , attribute ) do
3251
3259
resource
3252
3260
|> Ash.Resource.Info . relationships ( )
@@ -3581,22 +3589,6 @@ defmodule AshPostgres.MigrationGenerator do
3581
3589
[ "array" , sanitize_type ( type , size , scale , precision ) ]
3582
3590
end
3583
3591
3584
- defp sanitize_type ( :varchar , size , _scale , _precision ) when not is_nil ( size ) do
3585
- [ "varchar" , size ]
3586
- end
3587
-
3588
- defp sanitize_type ( :binary , size , _scale , _precision ) when not is_nil ( size ) do
3589
- [ "binary" , size ]
3590
- end
3591
-
3592
- defp sanitize_type ( :decimal , _size , scale , precision ) do
3593
- [ "decimal" , precision , scale ]
3594
- end
3595
-
3596
- defp sanitize_type ( type , size , precision , decimal ) when is_tuple ( type ) do
3597
- sanitize_type ( elem ( type , 0 ) , size , precision , decimal )
3598
- end
3599
-
3600
3592
defp sanitize_type ( type , _ , _ , _ ) do
3601
3593
type
3602
3594
end
@@ -3686,27 +3678,6 @@ defmodule AshPostgres.MigrationGenerator do
3686
3678
defp load_attribute ( attribute , table ) do
3687
3679
type = load_type ( attribute . type )
3688
3680
3689
- { type , size , scale , precision } =
3690
- case type do
3691
- { :varchar , size } ->
3692
- { :varchar , size , nil , nil }
3693
-
3694
- { :binary , size } ->
3695
- { :binary , size , nil , nil }
3696
-
3697
- { other , size } when is_atom ( other ) and is_integer ( size ) ->
3698
- { other , size , nil , nil }
3699
-
3700
- { :decimal , precision } ->
3701
- { :decimal , nil , nil , precision }
3702
-
3703
- { :decimal , precision , scale } ->
3704
- { :decimal , nil , precision , scale }
3705
-
3706
- other ->
3707
- { other , nil , nil , nil }
3708
- end
3709
-
3710
3681
attribute =
3711
3682
if Map . has_key? ( attribute , :name ) do
3712
3683
Map . put ( attribute , :source , maybe_to_atom ( attribute . name ) )
@@ -3716,9 +3687,9 @@ defmodule AshPostgres.MigrationGenerator do
3716
3687
3717
3688
attribute
3718
3689
|> Map . put ( :type , type )
3719
- |> Map . put ( :size , size )
3720
- |> Map . put ( :precision , precision )
3721
- |> Map . put ( :scale , scale )
3690
+ |> Map . put_new ( :size , nil )
3691
+ |> Map . put_new ( :precision , nil )
3692
+ |> Map . put_new ( :scale , nil )
3722
3693
|> Map . put_new ( :default , "nil" )
3723
3694
|> Map . update! ( :default , & ( & 1 || "nil" ) )
3724
3695
|> Map . update! ( :references , fn
@@ -3797,25 +3768,7 @@ defmodule AshPostgres.MigrationGenerator do
3797
3768
{ :array , load_type ( type ) }
3798
3769
end
3799
3770
3800
- defp load_type ( [ "varchar" , size ] ) do
3801
- { :varchar , size }
3802
- end
3803
-
3804
- defp load_type ( [ "binary" , size ] ) do
3805
- { :binary , size }
3806
- end
3807
-
3808
- defp load_type ( [ "decimal" , precision ] ) do
3809
- { :decimal , precision }
3810
- end
3811
-
3812
- defp load_type ( [ "decimal" , precision , scale ] ) do
3813
- { :decimal , precision , scale }
3814
- end
3815
-
3816
- defp load_type ( [ string , size ] ) when is_binary ( string ) and is_integer ( size ) do
3817
- { String . to_existing_atom ( string ) , size }
3818
- end
3771
+ defp load_type ( [ type | _ ] ) , do: String . to_existing_atom ( type )
3819
3772
3820
3773
defp load_type ( type ) do
3821
3774
maybe_to_atom ( type )
0 commit comments