Skip to content

Commit 127ed68

Browse files
authored
Update drop_if_exists docs to include constraints (#663)
1 parent f0cdeda commit 127ed68

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/ecto/migration.ex

+10-7
Original file line numberDiff line numberDiff line change
@@ -718,14 +718,19 @@ defmodule Ecto.Migration do
718718
end
719719

720720
@doc """
721-
Drops a table or index if it exists.
721+
Drops one of the following if it exists:
722+
723+
* an index
724+
* a table
725+
* a constraint
722726
723727
Does not raise an error if the specified table or index does not exist.
724728
725729
## Examples
726730
727731
drop_if_exists index("posts", [:name])
728732
drop_if_exists table("posts")
733+
drop_if_exists constraint("products", "price_must_be_positive")
729734
drop_if_exists index("posts", [:name]), mode: :cascade
730735
drop_if_exists table("posts"), mode: :cascade
731736
@@ -736,12 +741,10 @@ defmodule Ecto.Migration do
736741
on the table. Default is `:restrict`
737742
738743
"""
739-
def drop_if_exists(%{} = index_or_table, opts \\ []) when is_list(opts) do
740-
Runner.execute(
741-
{:drop_if_exists, __prefix__(index_or_table), Keyword.get(opts, :mode, :restrict)}
742-
)
743-
744-
index_or_table
744+
def drop_if_exists(%{} = index_or_table_or_constraint, opts \\ []) when is_list(opts) do
745+
mode = Keyword.get(opts, :mode, :restrict)
746+
Runner.execute({:drop_if_exists, __prefix__(index_or_table_or_constraint), mode})
747+
index_or_table_or_constraint
745748
end
746749

747750
@doc """

0 commit comments

Comments
 (0)