Skip to content

Commit 969ce15

Browse files
MySql/SQL Server raise for {:nilify, columns} on_delete action
1 parent 89bf043 commit 969ce15

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/ecto/adapters/myxql/connection.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,9 @@ if Code.ensure_loaded?(MyXQL) do
10501050
defp reference_column_type(type, opts), do: column_type(type, opts)
10511051

10521052
defp reference_on_delete(:nilify_all), do: " ON DELETE SET NULL"
1053+
defp reference_on_delete({:nilify, _columns}) do
1054+
error!(nil, "MySQL adapter does not support the `{:nilify, columns}` action for `:on_delete`")
1055+
end
10531056
defp reference_on_delete(:delete_all), do: " ON DELETE CASCADE"
10541057
defp reference_on_delete(:restrict), do: " ON DELETE RESTRICT"
10551058
defp reference_on_delete(_), do: []

lib/ecto/adapters/tds/connection.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,9 @@ if Code.ensure_loaded?(Tds) do
15021502
defp reference_column_type(type, opts), do: column_type(type, opts)
15031503

15041504
defp reference_on_delete(:nilify_all), do: " ON DELETE SET NULL"
1505+
defp reference_on_delete({:nilify, _columns}) do
1506+
error!(nil, "Tds adapter does not support the `{:nilify, columns}` action for `:on_delete`")
1507+
end
15051508
defp reference_on_delete(:delete_all), do: " ON DELETE CASCADE"
15061509
defp reference_on_delete(:nothing), do: " ON DELETE NO ACTION"
15071510
defp reference_on_delete(_), do: []

test/ecto/adapters/myxql_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,12 @@ defmodule Ecto.Adapters.MyXQLTest do
12261226
CONSTRAINT `posts_category_6_fkey` FOREIGN KEY (`category_6`,`here`) REFERENCES `categories`(`id`,`there`) ON DELETE SET NULL,
12271227
PRIMARY KEY (`id`)) ENGINE = INNODB
12281228
""" |> remove_newlines]
1229+
1230+
create = {:create, table(:posts),
1231+
[{:add, :category_1, %Reference{table: :categories, on_delete: {:nilify, [:category_1]}}, []}]}
1232+
1233+
msg = "MySQL adapter does not support the `{:nilify, columns}` action for `:on_delete`"
1234+
assert_raise ArgumentError, msg, fn -> execute_ddl(create) end
12291235
end
12301236

12311237
test "create table with options" do

test/ecto/adapters/tds_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,12 @@ defmodule Ecto.Adapters.TdsTest do
12801280
|> remove_newlines
12811281
|> Kernel.<>(" ")
12821282
]
1283+
1284+
create = {:create, table(:posts),
1285+
[{:add, :category_1, %Reference{table: :categories, on_delete: {:nilify, [:category_1]}}, []}]}
1286+
1287+
msg = "Tds adapter does not support the `{:nilify, columns}` action for `:on_delete`"
1288+
assert_raise ArgumentError, msg, fn -> execute_ddl(create) end
12831289
end
12841290

12851291
test "create table with options" do

0 commit comments

Comments
 (0)