From d7ecccdbcab14744ab3f2d220fec69d79c420a6a Mon Sep 17 00:00:00 2001 From: Nathan Long Date: Wed, 20 Apr 2016 17:41:27 -0400 Subject: [PATCH] Call them exclusion constraints, not exclude constraints (#1384) This matches the PostgreSQL docs --- CHANGELOG.md | 2 +- integration_test/pg/constraints_test.exs | 6 +++--- lib/ecto/adapters/mysql/connection.ex | 2 +- lib/ecto/changeset.ex | 8 ++++---- lib/ecto/migration.ex | 2 +- test/ecto/adapters/mysql_test.exs | 2 +- test/ecto/changeset_test.exs | 6 +++--- test/ecto/migration_test.exs | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaacf9dec6..34891e1c20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -146,7 +146,7 @@ Finally, Ecto now allows putting existing records in changesets, and the proper * [Migration] Support `:on_update` for `Ecto.Migrate.references` * [Migration] Use pool of 1 connection for `mix ecto.migrate/rollback` * [Mix] Automatically reenable migration and repository management tasks after execution - * [Postgres] Add migration and changeset support for PostgreSQL exclusion constraints. Example: `create constraint(:sizes, :cannot_overlap, exclude: ~s|gist (int4range("min", "max", '[]') WITH &&)|)` and `exclude_constraint(changeset, :sizes, name: :cannot_overlap, message: "must not overlap")` + * [Postgres] Add migration and changeset support for PostgreSQL exclusion constraints. Example: `create constraint(:sizes, :cannot_overlap, exclude: ~s|gist (int4range("min", "max", '[]') WITH &&)|)` and `exclusion_constraint(changeset, :sizes, name: :cannot_overlap, message: "must not overlap")` * [Postgres] Add migration and changeset support for PostgreSQL check constraints. Example: `create constraint(:products, "positive_price", check: "price > 0")` and `check_constraint(changeset, :price, name: :positive_price, message: "must be greater than zero")` * [Query] Allow the `:on` field to be specified with association joins * [Query] Support expressions in map keys in `select` in queries. Example: `from p in Post, select: %{p.title => p.visitors}` diff --git a/integration_test/pg/constraints_test.exs b/integration_test/pg/constraints_test.exs index 806a35dafb..80b268c2d9 100644 --- a/integration_test/pg/constraints_test.exs +++ b/integration_test/pg/constraints_test.exs @@ -36,7 +36,7 @@ defmodule Ecto.Integration.ConstraintsTest do up(PoolRepo, 20040906120000, ConstraintMigration, log: false) end - test "creating, using, and dropping an exclude constraint" do + test "creating, using, and dropping an exclusion constraint" do changeset = Ecto.Changeset.change(%Constraint{}, from: 0, to: 10) {:ok, _} = PoolRepo.insert(changeset) @@ -56,14 +56,14 @@ defmodule Ecto.Integration.ConstraintsTest do exception = assert_raise Ecto.ConstraintError, message, fn -> overlapping_changeset - |> Ecto.Changeset.exclude_constraint(:from) + |> Ecto.Changeset.exclusion_constraint(:from) |> PoolRepo.insert() end assert exception.message =~ "exclude: cannot_overlap" {:error, changeset} = overlapping_changeset - |> Ecto.Changeset.exclude_constraint(:from, name: :cannot_overlap) + |> Ecto.Changeset.exclusion_constraint(:from, name: :cannot_overlap) |> PoolRepo.insert() assert changeset.errors == [from: {"violates an exclusion constraint", []}] assert changeset.data.__meta__.state == :built diff --git a/lib/ecto/adapters/mysql/connection.ex b/lib/ecto/adapters/mysql/connection.ex index 30ca32d9db..81c75ad781 100644 --- a/lib/ecto/adapters/mysql/connection.ex +++ b/lib/ecto/adapters/mysql/connection.ex @@ -520,7 +520,7 @@ if Code.ensure_loaded?(Mariaex) do def execute_ddl({:create, %Constraint{check: check}}) when is_binary(check), do: error!(nil, "MySQL adapter does not support check constraints") def execute_ddl({:create, %Constraint{exclude: exclude}}) when is_binary(exclude), - do: error!(nil, "MySQL adapter does not support exclude constraints") + do: error!(nil, "MySQL adapter does not support exclusion constraints") def execute_ddl({:drop, %Index{}=index}) do assemble(["DROP INDEX", diff --git a/lib/ecto/changeset.ex b/lib/ecto/changeset.ex index 89c729258d..fbf58ac238 100644 --- a/lib/ecto/changeset.ex +++ b/lib/ecto/changeset.ex @@ -1706,10 +1706,10 @@ defmodule Ecto.Changeset do end @doc """ - Checks for a exclude constraint in the given field. + Checks for a exclusion constraint in the given field. - The exclude constraint works by relying on the database to check - if the exclude constraint has been violated or not and, if so, + The exclusion constraint works by relying on the database to check + if the exclusion constraint has been violated or not and, if so, Ecto converts it into a changeset error. ## Options @@ -1721,7 +1721,7 @@ defmodule Ecto.Changeset do explicitly for complex cases """ - def exclude_constraint(changeset, field, opts \\ []) do + def exclusion_constraint(changeset, field, opts \\ []) do constraint = opts[:name] || "#{get_source(changeset)}_#{field}_exclusion" message = message(opts, "violates an exclusion constraint") add_constraint(changeset, :exclude, to_string(constraint), field, {message, []}) diff --git a/lib/ecto/migration.ex b/lib/ecto/migration.ex index 137bda01c6..fcf1cd4b5d 100644 --- a/lib/ecto/migration.ex +++ b/lib/ecto/migration.ex @@ -703,7 +703,7 @@ defmodule Ecto.Migration do end @doc ~S""" - Defines a constraint (either a check constraint or an exclude constraint) to be evaluated by the database when a row is inserted or updated. + Defines a constraint (either a check constraint or an exclusion constraint) to be evaluated by the database when a row is inserted or updated. ## Examples diff --git a/test/ecto/adapters/mysql_test.exs b/test/ecto/adapters/mysql_test.exs index e8af1dfec9..3eac72f921 100644 --- a/test/ecto/adapters/mysql_test.exs +++ b/test/ecto/adapters/mysql_test.exs @@ -652,7 +652,7 @@ defmodule Ecto.Adapters.MySQLTest do assert SQL.execute_ddl(create) end - assert_raise ArgumentError, "MySQL adapter does not support exclude constraints", fn -> + assert_raise ArgumentError, "MySQL adapter does not support exclusion constraints", fn -> create = {:create, constraint(:products, "bar", exclude: "price")} assert SQL.execute_ddl(create) end diff --git a/test/ecto/changeset_test.exs b/test/ecto/changeset_test.exs index 8bab53bb36..c454aa3240 100644 --- a/test/ecto/changeset_test.exs +++ b/test/ecto/changeset_test.exs @@ -969,13 +969,13 @@ defmodule Ecto.ChangesetTest do end end - test "exclude_constraint/3" do - changeset = change(%Post{}) |> exclude_constraint(:title) + test "exclusion_constraint/3" do + changeset = change(%Post{}) |> exclusion_constraint(:title) assert changeset.constraints == [%{type: :exclude, field: :title, constraint: "posts_title_exclusion", error: {"violates an exclusion constraint", []}}] - changeset = change(%Post{}) |> exclude_constraint(:title, name: :whatever, message: "is invalid") + changeset = change(%Post{}) |> exclusion_constraint(:title, name: :whatever, message: "is invalid") assert changeset.constraints == [%{type: :exclude, field: :title, constraint: "whatever", error: {"is invalid", []}}] diff --git a/test/ecto/migration_test.exs b/test/ecto/migration_test.exs index 2c848ea0ff..0139dc2bd0 100644 --- a/test/ecto/migration_test.exs +++ b/test/ecto/migration_test.exs @@ -167,7 +167,7 @@ defmodule Ecto.MigrationTest do assert {:create, %Constraint{}} = last_command() end - test "forward: creates an exclude constraint" do + test "forward: creates an exclusion constraint" do create constraint(:posts, :price, exclude: "price") flush assert {:create, %Constraint{}} = last_command()