Skip to content

Commit

Permalink
Validate keys in migrations (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed Jan 23, 2024
1 parent 22334da commit c0e97cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/ecto/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ defmodule Ecto.Migration do
end

def table(name, opts) when is_binary(name) and is_list(opts) do
struct(%Table{name: name}, opts)
struct!(%Table{name: name}, opts)
end

@doc ~S"""
Expand Down Expand Up @@ -926,7 +926,7 @@ defmodule Ecto.Migration do

def index(table, columns, opts) when is_binary(table) and is_list(columns) and is_list(opts) do
validate_index_opts!(opts)
index = struct(%Index{table: table, columns: columns}, opts)
index = struct!(%Index{table: table, columns: columns}, opts)
%{index | name: index.name || default_index_name(index)}
end

Expand Down Expand Up @@ -1417,7 +1417,7 @@ defmodule Ecto.Migration do

def references(table, opts) when is_binary(table) and is_list(opts) do
opts = Keyword.merge(foreign_key_repo_opts(), opts)
reference = struct(%Reference{table: table}, opts)
reference = struct!(%Reference{table: table}, opts)
check_on_delete!(reference.on_delete)
check_on_update!(reference.on_update)

Expand Down Expand Up @@ -1486,7 +1486,7 @@ defmodule Ecto.Migration do
end

def constraint(table, name, opts) when is_binary(table) and is_list(opts) do
struct(%Constraint{table: table, name: name}, opts)
struct!(%Constraint{table: table, name: name}, opts)
end

@doc "Executes queue migration commands."
Expand Down
2 changes: 1 addition & 1 deletion test/ecto/migration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ defmodule Ecto.MigrationTest do

assert result == table(:posts)

create table = table(:posts, primary_key: false, timestamps: false) do
create table = table(:posts, primary_key: false) do
add :title, :string
end

Expand Down

0 comments on commit c0e97cb

Please sign in to comment.