Skip to content

Commit c0e97cb

Browse files
authored
Validate keys in migrations (#592)
1 parent 22334da commit c0e97cb

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

lib/ecto/migration.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ defmodule Ecto.Migration do
760760
end
761761

762762
def table(name, opts) when is_binary(name) and is_list(opts) do
763-
struct(%Table{name: name}, opts)
763+
struct!(%Table{name: name}, opts)
764764
end
765765

766766
@doc ~S"""
@@ -926,7 +926,7 @@ defmodule Ecto.Migration do
926926

927927
def index(table, columns, opts) when is_binary(table) and is_list(columns) and is_list(opts) do
928928
validate_index_opts!(opts)
929-
index = struct(%Index{table: table, columns: columns}, opts)
929+
index = struct!(%Index{table: table, columns: columns}, opts)
930930
%{index | name: index.name || default_index_name(index)}
931931
end
932932

@@ -1417,7 +1417,7 @@ defmodule Ecto.Migration do
14171417

14181418
def references(table, opts) when is_binary(table) and is_list(opts) do
14191419
opts = Keyword.merge(foreign_key_repo_opts(), opts)
1420-
reference = struct(%Reference{table: table}, opts)
1420+
reference = struct!(%Reference{table: table}, opts)
14211421
check_on_delete!(reference.on_delete)
14221422
check_on_update!(reference.on_update)
14231423

@@ -1486,7 +1486,7 @@ defmodule Ecto.Migration do
14861486
end
14871487

14881488
def constraint(table, name, opts) when is_binary(table) and is_list(opts) do
1489-
struct(%Constraint{table: table, name: name}, opts)
1489+
struct!(%Constraint{table: table, name: name}, opts)
14901490
end
14911491

14921492
@doc "Executes queue migration commands."

test/ecto/migration_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ defmodule Ecto.MigrationTest do
276276

277277
assert result == table(:posts)
278278

279-
create table = table(:posts, primary_key: false, timestamps: false) do
279+
create table = table(:posts, primary_key: false) do
280280
add :title, :string
281281
end
282282

0 commit comments

Comments
 (0)