Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ash.codegen generates wrong sequence of migration #1394

Open
mudspot opened this issue Aug 17, 2024 · 0 comments
Open

ash.codegen generates wrong sequence of migration #1394

mudspot opened this issue Aug 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mudspot
Copy link

mudspot commented Aug 17, 2024

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

  1. Create a Resource ResourceX, with attribute :is_authentic, :boolean
  2. mix ash.codegen create_resource_x_table
  3. mix ecto.migrate
  4. Edit the ResourceX file and change the attribute line to attribute :is_spicy, :boolean
  5. mix ash.codegen modify_resource_x_table
  6. mix ecto.migrate
    All good up till here
  7. 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.

@mudspot mudspot added bug Something isn't working needs review labels Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Up Next
Development

No branches or pull requests

2 participants