Skip to content

MySql/SQL Server raise for {:nilify, columns} on_delete action #475

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ecto/adapters/myxql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,9 @@ if Code.ensure_loaded?(MyXQL) do
defp reference_column_type(type, opts), do: column_type(type, opts)

defp reference_on_delete(:nilify_all), do: " ON DELETE SET NULL"
defp reference_on_delete({:nilify, _columns}) do
error!(nil, "MySQL adapter does not support the `{:nilify, columns}` action for `:on_delete`")
end
defp reference_on_delete(:delete_all), do: " ON DELETE CASCADE"
defp reference_on_delete(:restrict), do: " ON DELETE RESTRICT"
defp reference_on_delete(_), do: []
Expand Down
3 changes: 3 additions & 0 deletions lib/ecto/adapters/tds/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,9 @@ if Code.ensure_loaded?(Tds) do
defp reference_column_type(type, opts), do: column_type(type, opts)

defp reference_on_delete(:nilify_all), do: " ON DELETE SET NULL"
defp reference_on_delete({:nilify, _columns}) do
error!(nil, "Tds adapter does not support the `{:nilify, columns}` action for `:on_delete`")
end
defp reference_on_delete(:delete_all), do: " ON DELETE CASCADE"
defp reference_on_delete(:nothing), do: " ON DELETE NO ACTION"
defp reference_on_delete(_), do: []
Expand Down
6 changes: 6 additions & 0 deletions test/ecto/adapters/myxql_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,12 @@ defmodule Ecto.Adapters.MyXQLTest do
CONSTRAINT `posts_category_6_fkey` FOREIGN KEY (`category_6`,`here`) REFERENCES `categories`(`id`,`there`) ON DELETE SET NULL,
PRIMARY KEY (`id`)) ENGINE = INNODB
""" |> remove_newlines]

create = {:create, table(:posts),
[{:add, :category_1, %Reference{table: :categories, on_delete: {:nilify, [:category_1]}}, []}]}

msg = "MySQL adapter does not support the `{:nilify, columns}` action for `:on_delete`"
assert_raise ArgumentError, msg, fn -> execute_ddl(create) end
end

test "create table with options" do
Expand Down
6 changes: 6 additions & 0 deletions test/ecto/adapters/tds_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,12 @@ defmodule Ecto.Adapters.TdsTest do
|> remove_newlines
|> Kernel.<>(" ")
]

create = {:create, table(:posts),
[{:add, :category_1, %Reference{table: :categories, on_delete: {:nilify, [:category_1]}}, []}]}

msg = "Tds adapter does not support the `{:nilify, columns}` action for `:on_delete`"
assert_raise ArgumentError, msg, fn -> execute_ddl(create) end
end

test "create table with options" do
Expand Down