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

Commitbaf4e32

Browse files
authored
fix: Use new attribute source in down migration (ash-project#604)
closes:ash-project#582When an attribute is renamed, alongside other changes to it (like changing default or not null constraint), the generated up migration first renames the column, then modifies it.For the generated down migration, the order of operations is reversed, so we need to use the new column name when modifying the column, before renaming it back.
1 parent9963270 commitbaf4e32

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

‎lib/migration_generator/operation.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do
752752
up(%{
753753
op
754754
|old_attribute:op.new_attribute,
755-
new_attribute:op.old_attribute,
755+
new_attribute:Map.put(op.old_attribute,:source,op.new_attribute.source),
756756
old_multitenancy:op.multitenancy,
757757
multitenancy:op.old_multitenancy
758758
})

‎test/migration_generator_test.exs‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,41 @@ defmodule AshPostgres.MigrationGeneratorTest do
825825
Enum.sort(Path.wildcard("test_migration_path/**/*_migrate_resources*.exs"))
826826
|>Enum.reject(&String.contains?(&1,"extensions"))
827827

828-
assertFile.read!(file2)=~~S[rename table(:posts, prefix: "example"), :title, to: :name]
829-
assertFile.read!(file2)=~~S[modify :title, :text, null: true, default: nil]
828+
contents=File.read!(file2)
829+
830+
[up_side,down_side]=String.split(contents,"def down",parts:2)
831+
832+
up_side_parts=
833+
String.split(up_side,"\n",trim:true)
834+
|>Enum.map(&String.trim/1)
835+
836+
up_rename_index=
837+
Enum.find_index(up_side_parts,fnx->
838+
x==~S[rename table(:posts, prefix: "example"), :title, to: :name]
839+
end)
840+
841+
up_modify_index=
842+
Enum.find_index(up_side_parts,fnx->
843+
x==~S[modify :name, :text, null: false, default: "fred"]
844+
end)
845+
846+
assertup_rename_index<up_modify_index
847+
848+
down_side_parts=
849+
String.split(down_side,"\n",trim:true)
850+
|>Enum.map(&String.trim/1)
851+
852+
down_modify_index=
853+
Enum.find_index(down_side_parts,fnx->
854+
x==~S[modify :name, :text, null: true, default: nil]
855+
end)
856+
857+
down_rename_index=
858+
Enum.find_index(down_side_parts,fnx->
859+
x==~S[rename table(:posts, prefix: "example"), :name, to: :title]
860+
end)
861+
862+
assertdown_modify_index<down_rename_index
830863
end
831864
end
832865

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp