Skip to content

alter table rename doesn't alter fkey contraints #178

@mhelmersen-maskon

Description

@mhelmersen-maskon

Code of Conduct

  • I agree to follow this project's Code of Conduct

AI Policy

  • I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.

Versions

I used mix ash.codegen to run migration for my project.
The only changes i had done to my resource was changing the name of two relationships. Following this, i was prompted with: "Are you renaming "column_name" [Yn] ? my input: y
What are you renaming it to?: "new_column_name_1", "new_column_name_2", my input: "new_column_name_1".
Are you renaming "column_name_2" to "new_column_name_2" [Yn] ? my input: y
it successfully created a migration, but the proceeding migration had 2 :
rename table("table_name"), "column_name_1", to: "new_column_name_1"
rename table("table_name"), "column_name_2", to: "new_column_name_2"
and additionally it had:
alter table("table_name") do
add "new_column_name_2
references (
name: "table_name_new_column_name_2"
)

This would in my understanding try to alter the table and add a new column with the same column_name as the one that was just renamed?

versions:

    {:dialyxir, "~> 1.4", only: [:dev], runtime: false},
    {:credo, "~> 1.7", only: [:dev, :test], runtime: false},
    {:sourceror, "~> 1.7", only: [:dev, :test]},
    {:logger_file_backend, "~> 0.0.14"},
    {:phoenix, "~> 1.8.0", override: true},
    {:bandit, "~> 1.6"},
    {:phoenix_ecto, "~> 4.6"},
    {:ecto_sql, "~> 3.12"},
    {:phoenix_html, "~> 4.1"},
    {:phoenix_live_reload, "~> 1.2", only: :dev},
    {:phoenix_live_view, "~> 1.0"},
    {:floki, "~> 0.35", only: :test},
    {:phoenix_live_dashboard, "~> 0.8.3"},
    {:esbuild, "~> 0.9", runtime: Mix.env() == :dev},
    {:tailwind, "~> 0.3.1", runtime: Mix.env() == :dev},
    {:heroicons, github: "tailwindlabs/heroicons", tag: "v2.1.1", sparse: "optimized", app: false, compile: false, depth: 1},
    {:telemetry_metrics, "~> 1.0", override: true},
    {:telemetry_poller, "~> 1.0"},
    {:gettext, "~> 0.26"},
    {:jason, "~> 1.2"},
    {:burrito, "~> 1.2"},
    {:iconify_ex, "~> 0.6.1"},
    {:typed_struct, "~> 0.2"},
    {:uniq, "~> 0.6.1"},
    {:rustler_precompiled, "~> 0.8"},
    {:sparkline_svg, "~> 0.5.0"},
    {:multipart, "~> 0.4.0"},
    {:statistex, "~> 1.0.0"},
    {:libcluster, "~> 3.4"},
    {:timex, "~> 3.7"},

    # Cache
    {:cachex, "~> 4.1"},

    # Ash
    {:picosat_elixir, "~> 0.2.3"},
    {:ash, "~> 3.5"},
    {:ash_sqlite, "~> 0.2"},
    {:ash_phoenix, "~> 2.3.9"},

    # Websocket
    {:websockex, "~> 0.4.3"},

    # HTTP Client
    {:req, "~> 0.5.10"},

    # File system
    {:file_system, "~> 1.0"},

    # Serial Port
    {:circuits_uart, "~> 1.5"},

    # Testing
    # {:smokestack, path: "../forks/smokestack", only: [:test]},
    {:faker, "~> 0.18.0", only: [:test]}

Erlang/OTP 27 [erts-15.2.7] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.18.3 (compiled with Erlang/OTP 27)

Operating system

windows 11

Current Behavior

(Mix) Could not start application sky_client: exited in: SkyClient.Application.start(:normal, []) ** (EXIT) an exception was raised: ** (Exqlite.Error) duplicate column name: im_needle_id ALTER TABLE "ses_config" ADD COLUMN "im_needle_id" TEXT CONSTRAINT "ses_config_im_needle_id_fkey" REFEREb/ecto/repo/transaction.ex:7: anonymous fn/2 in Ecto.Repo.Transaction.transact/4 (ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:1458: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4 (db_connection 2.8.0) lib/db_connection.ex:1753: DBConnection.run_transaction/4 (ecto_sql 3.13.2) lib/ecto/migrator.ex:354: Ecto.Migrator.run_maybe_in_transaction/5 (elixir 1.18.3) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2 (elixir 1.18.3) lib/task/supervised.ex:36: Task.Supervised.reply/4

def up do rename table(:ses_config), :abdomen_needle_size_id, to: :abdomen_needle_id rename table(:ses_config), :im_needle_size_id, to: :im_needle_id alter table(:ses_config) do add :im_needle_id, references(:inv_inventory_item, column: :id, name: "ses_config_im_needle_id_fkey", type: :uuid ) end end

Reproduction

To reproduce, i would try to alter the column_id of any existing column(s), with mix ash.codegen to see if with exqlite it will correctly alter the columns. If as written above it renames the columns, then tries to add the same column, with new f_key, reproduction is successful.

Expected Behavior

I wanted the columns, with their relationships to function as previously, just with altered column_id.

so i would expect, drop old column_id, and add new column_id

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    Status

    Someday

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions