Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit250f8b1

Browse files
committed
fix: always drop constraints before modifying
fix: properly compare old references and new references
1 parent0a80362 commit250f8b1

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

‎lib/migration_generator/migration_generator.ex‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,8 @@ defmodule AshPostgres.MigrationGenerator do
11221122
else
11231123
[
11241124
%Operation.AlterAttribute{
1125-
new_attribute:new_attribute,
1126-
old_attribute:old_attribute,
1125+
new_attribute:Map.delete(new_attribute,:references),
1126+
old_attribute:Map.delete(old_attribute,:references),
11271127
table:snapshot.table
11281128
}
11291129
]
@@ -1414,14 +1414,17 @@ defmodule AshPostgres.MigrationGenerator do
14141414
end
14151415

14161416
defpconfigured_reference(resource,attribute,relationship)do
1417-
resource
1418-
|>AshPostgres.references()
1419-
|>Enum.find(&(&1.relationship==relationship))
1420-
|>Kernel.||(%{
1421-
on_delete:nil,
1422-
on_update:nil,
1423-
name:"#{AshPostgres.table(resource)}_#{attribute}_fkey"
1424-
})
1417+
ref=
1418+
resource
1419+
|>AshPostgres.references()
1420+
|>Enum.find(&(&1.relationship==relationship))
1421+
|>Kernel.||(%{
1422+
on_delete:nil,
1423+
on_update:nil,
1424+
name:nil
1425+
})
1426+
1427+
Map.put(ref,:name,ref.name||"#{AshPostgres.table(resource)}_#{attribute}_fkey")
14251428
end
14261429

14271430
defpmigration_type({:array,type}),do:{:array,migration_type(type)}
@@ -1560,7 +1563,9 @@ defmodule AshPostgres.MigrationGenerator do
15601563
|>Map.update!(:destination_field,&String.to_atom/1)
15611564
|>Map.put_new(:on_delete,nil)
15621565
|>Map.put_new(:on_update,nil)
1563-
|>Map.put_new(:name,"#{table}_#{attribute.name}")
1566+
|>Map.update!(:on_delete,&(&1&&String.to_atom(&1)))
1567+
|>Map.update!(:on_update,&(&1&&String.to_atom(&1)))
1568+
|>Map.put(:name,Map.get(references,:name)||"#{table}_#{attribute.name}")
15641569
|>Map.put_new(:multitenancy,%{
15651570
attribute:nil,
15661571
strategy:nil,

‎lib/migration_generator/operation.ex‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,21 @@ defmodule AshPostgres.MigrationGenerator.Operation do
357357
# We only need to drop it before altering an attribute with `references/3`
358358
defstruct[:attribute,:table,:multitenancy,:direction,no_phase:true]
359359

360-
defup(%{table:table,references:reference,direction::up})do
360+
defup(%{table:table,attribute:%{references:reference},direction::up})do
361361
"drop constraint(:#{table},#{inspect(reference.name)})"
362362
end
363363

364-
defup(_),do:""
364+
defup(_)do
365+
""
366+
end
365367

366-
defdown(%{table:table,references:reference,direction::down})do
368+
defdown(%{table:table,attribute:%{references:reference},direction::down})do
367369
"drop constraint(:#{table},#{inspect(reference.name)})"
368370
end
369371

370-
defdown(_),do:""
372+
defdown(_)do
373+
""
374+
end
371375
end
372376

373377
defmoduleRenameAttributedo

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp