Skip to content

Commit fc6dfd5

Browse files
committed
fix: don't set size, precision, or scale for references
fixes #665
1 parent 1f29391 commit fc6dfd5

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

lib/migration_generator/operation.ex

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ defmodule AshPostgres.MigrationGenerator.Operation do
188188
"type: #{inspect(reference_type(attribute, reference))}",
189189
option("prefix", destination_schema),
190190
on_delete(reference),
191-
on_update(reference),
192-
size,
193-
maybe_add_precision(attribute[:precision]),
194-
maybe_add_scale(attribute[:scale])
191+
on_update(reference)
195192
],
196193
")",
194+
size,
195+
maybe_add_precision(attribute[:precision]),
196+
maybe_add_scale(attribute[:scale]),
197197
maybe_add_default(attribute.default),
198198
maybe_add_primary_key(attribute.primary_key?),
199199
maybe_add_null(attribute.allow_nil?)
@@ -230,13 +230,13 @@ defmodule AshPostgres.MigrationGenerator.Operation do
230230
option("prefix", destination_schema),
231231
"name: #{inspect(reference.name)}",
232232
"type: #{inspect(reference_type(attribute, reference))}",
233-
size,
234-
maybe_add_precision(attribute[:precision]),
235-
maybe_add_scale(attribute[:scale]),
236233
on_delete(reference),
237234
on_update(reference)
238235
],
239236
")",
237+
size,
238+
maybe_add_precision(attribute[:precision]),
239+
maybe_add_scale(attribute[:scale]),
240240
maybe_add_default(attribute.default),
241241
maybe_add_primary_key(attribute.primary_key?),
242242
maybe_add_null(attribute.allow_nil?)
@@ -374,13 +374,13 @@ defmodule AshPostgres.MigrationGenerator.Operation do
374374
"name: #{inspect(reference.name)}",
375375
"type: #{inspect(reference_type(attribute, reference))}",
376376
option("prefix", destination_schema),
377-
size,
378-
maybe_add_precision(attribute[:precision]),
379-
maybe_add_scale(attribute[:scale]),
380377
on_delete(reference),
381378
on_update(reference)
382379
],
383380
")",
381+
size,
382+
maybe_add_precision(attribute[:precision]),
383+
maybe_add_scale(attribute[:scale]),
384384
maybe_add_default(attribute.default),
385385
maybe_add_primary_key(attribute.primary_key?),
386386
maybe_add_null(attribute.allow_nil?)
@@ -415,13 +415,13 @@ defmodule AshPostgres.MigrationGenerator.Operation do
415415
"name: #{inspect(reference.name)}",
416416
"type: #{inspect(reference_type(attribute, reference))}",
417417
option("prefix", destination_schema),
418-
size,
419-
maybe_add_precision(attribute[:precision]),
420-
maybe_add_scale(attribute[:scale]),
421418
on_delete(reference),
422419
on_update(reference)
423420
],
424421
")",
422+
size,
423+
maybe_add_precision(attribute[:precision]),
424+
maybe_add_scale(attribute[:scale]),
425425
maybe_add_default(attribute.default),
426426
maybe_add_primary_key(attribute.primary_key?),
427427
maybe_add_null(attribute.allow_nil?)
@@ -564,6 +564,13 @@ defmodule AshPostgres.MigrationGenerator.Operation do
564564
", null: #{attribute.allow_nil?}"
565565
end
566566

567+
size =
568+
if Map.get(attribute, :size) != Map.get(old_attribute, :size) do
569+
if attribute.size do
570+
", size: #{attribute.size}"
571+
end
572+
end
573+
567574
precision =
568575
if Map.get(attribute, :precision) != Map.get(old_attribute, :precision) do
569576
if attribute.precision do
@@ -578,7 +585,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do
578585
end
579586
end
580587

581-
"#{null}#{default}#{precision}#{scale}#{primary_key}"
588+
"#{null}#{default}#{size}#{precision}#{scale}#{primary_key}"
582589
end
583590

584591
def up(%{
@@ -616,19 +623,11 @@ defmodule AshPostgres.MigrationGenerator.Operation do
616623
) do
617624
with_match = with_match(reference)
618625

619-
size =
620-
if attribute[:size] do
621-
"size: #{attribute[:size]}"
622-
end
623-
624626
join([
625627
"references(:#{as_atom(table)}, column: #{inspect(destination_attribute)}",
626628
with_match,
627629
"name: #{inspect(reference.name)}",
628630
"type: #{inspect(reference_type(attribute, reference))}",
629-
size,
630-
maybe_add_precision(attribute[:precision]),
631-
maybe_add_scale(attribute[:scale]),
632631
"prefix: prefix()",
633632
on_delete(reference),
634633
on_update(reference),
@@ -656,19 +655,11 @@ defmodule AshPostgres.MigrationGenerator.Operation do
656655

657656
with_match = with_match(reference, source_attribute)
658657

659-
size =
660-
if attribute[:size] do
661-
"size: #{attribute[:size]}"
662-
end
663-
664658
join([
665659
"references(:#{as_atom(table)}, column: #{inspect(reference_attribute)}",
666660
with_match,
667661
"name: #{inspect(reference.name)}",
668662
"type: #{inspect(reference_type(attribute, reference))}",
669-
size,
670-
maybe_add_precision(attribute[:precision]),
671-
maybe_add_scale(attribute[:scale]),
672663
option("prefix", destination_schema),
673664
on_delete(reference),
674665
on_update(reference),
@@ -690,11 +681,6 @@ defmodule AshPostgres.MigrationGenerator.Operation do
690681
) do
691682
with_match = with_match(reference)
692683

693-
size =
694-
if attribute[:size] do
695-
"size: #{attribute[:size]}"
696-
end
697-
698684
destination_schema =
699685
if schema != destination_schema do
700686
destination_schema
@@ -705,7 +691,6 @@ defmodule AshPostgres.MigrationGenerator.Operation do
705691
with_match,
706692
"name: #{inspect(reference.name)}",
707693
"type: #{inspect(reference_type(attribute, reference))}",
708-
size,
709694
option("prefix", destination_schema),
710695
on_delete(reference),
711696
on_update(reference),
@@ -742,9 +727,6 @@ defmodule AshPostgres.MigrationGenerator.Operation do
742727
with_match,
743728
"name: #{inspect(reference.name)}",
744729
"type: #{inspect(reference_type(attribute, reference))}",
745-
size,
746-
maybe_add_precision(attribute[:precision]),
747-
maybe_add_scale(attribute[:scale]),
748730
option("prefix", destination_schema),
749731
on_delete(reference),
750732
on_update(reference),

0 commit comments

Comments
 (0)