ash.codegen
generates wrong sequence of migration #1394
Description
Describe the bug
When a boolean attribute in a Resource is renamed, the migration code generated by ash.codegen
will fail on rollback.
To Reproduce
- Create a Resource
ResourceX
, withattribute :is_authentic, :boolean
mix ash.codegen create_resource_x_table
mix ecto.migrate
- Edit the ResourceX file and change the attribute line to
attribute :is_spicy, :boolean
mix ash.codegen modify_resource_x_table
mix ecto.migrate
All good up till here- Rollback with
mix ecto.rollback -n 1
Fails
Expected behavior
I expect Step 7 above to work. I have added additional information in 2 sections below
Actual Generated Migration Code at Step 5
def up do
rename table(:resource_x), :is_authentic, to: :is_spicy
alter table(:resource_x) do
modify :is_spicy, :boolean
end
end
def down do
alter table(:resource_x) do
modify :is_authentic, :boolean
end
rename table(:resource_x), :is_spicy, to: :is_authentic
end
The sequence for def down
is incorrect
Expected/Correct Code
def down do
rename table(:resource_x), :is_spicy, to: :is_authentic
alter table(:resource_x) do
modify :is_authentic, :boolean
end
end
Runtime
-
Elixir version
Elixir 1.17.2 (compiled with Erlang/OTP 27)
-
Erlang version
27.0.1
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
-
OS
Linux prometheus 6.10.4-zen2-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Sun, 11 Aug 2024 16:18:46 +0000 x86_64 GNU/Linux
-
Ash version
-
any related extension versions
:ash, "3.4.1"
:ash_phoenix, "2.1.1"
:ash_postgres, "2.2.1"
:ash_sql, "0.2.30"
Add any other context about the problem here.
Metadata
Assignees
Labels
Type
Projects
Status
Someday