Skip to content

Commit

Permalink
reverse constraint validate options
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Sep 13, 2023
1 parent 27cf82b commit 79e5f6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/ecto/adapters/clickhouse/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ defmodule Ecto.Adapters.ClickHouse.Migration do

def execute_ddl({command, %Constraint{} = constraint}) when is_create(command) do
if constraint.comment do
raise "Clickhouse adapter does not support comments on check constraints"
raise "ClickHouse does not support comments on constraints"
end

unless constraint.validate do
raise "Clickhouse adapter does not support check constraints without validation on creation"
if constraint.validate do
raise "ClickHouse does not support CHECK constraints with validation on creation"
end

if constraint.exclude do
raise "Clickhouse adapter does not support exclude constraints"
raise "ClickHouse does not support exclusion constraints"
end

unless constraint.check do
raise "Clickhouse adapter requires check option for constraints"
raise "ClickHouse supports only CHECK constraints"
end

[
Expand Down
10 changes: 7 additions & 3 deletions test/ecto/adapters/clickhouse/connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2533,7 +2533,9 @@ defmodule Ecto.Adapters.ClickHouse.ConnectionTest do
end

test "create check constraint" do
create = {:create, constraint(:products, "price_must_be_positive", check: "price > 0")}
create =
{:create,
constraint(:products, "price_must_be_positive", check: "price > 0", validate: false)}

assert execute_ddl(create) == [
~s|ALTER TABLE "products" ADD CONSTRAINT "price_must_be_positive" CHECK (price > 0)|
Expand All @@ -2543,7 +2545,8 @@ defmodule Ecto.Adapters.ClickHouse.ConnectionTest do
{:create,
constraint(:products, "price_must_be_positive",
check: "price > 0",
prefix: "foo"
prefix: "foo",
validate: false
)}

assert execute_ddl(create) == [
Expand All @@ -2553,7 +2556,8 @@ defmodule Ecto.Adapters.ClickHouse.ConnectionTest do

test "create check constraint if not exists" do
create =
{:create_if_not_exists, constraint(:products, "price_must_be_positive", check: "price > 0")}
{:create_if_not_exists,
constraint(:products, "price_must_be_positive", check: "price > 0", validate: false)}

assert execute_ddl(create) == [
~s|ALTER TABLE "products" ADD CONSTRAINT IF NOT EXISTS "price_must_be_positive" CHECK (price > 0)|
Expand Down

0 comments on commit 79e5f6e

Please sign in to comment.