Skip to content

Commit be8c863

Browse files
format + small logging cleanup
1 parent 2096c33 commit be8c863

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

lib/ecto/adapters/myxql/connection.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,13 @@ if Code.ensure_loaded?(MyXQL) do
13801380

13811381
defp modifiers_expr(nil), do: []
13821382
defp modifiers_expr(modifiers) when is_binary(modifiers), do: [modifiers, ?\s]
1383-
defp modifiers_expr(other), do: error!(nil, "MySQL adapter expects :modifiers to be a string or nil, got #{inspect(other)}")
1383+
1384+
defp modifiers_expr(other),
1385+
do:
1386+
error!(
1387+
nil,
1388+
"MySQL adapter expects :modifiers to be a string or nil, got #{inspect(other)}"
1389+
)
13841390

13851391
defp options_expr(nil),
13861392
do: []

lib/ecto/adapters/postgres/connection.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,13 @@ if Code.ensure_loaded?(Postgrex) do
17641764

17651765
defp modifiers_expr(nil), do: []
17661766
defp modifiers_expr(modifiers) when is_binary(modifiers), do: [modifiers, ?\s]
1767-
defp modifiers_expr(other), do: error!(nil, "PostgreSQL adapter expects :modifiers to be a string or nil, got #{inspect(other)}")
1767+
1768+
defp modifiers_expr(other),
1769+
do:
1770+
error!(
1771+
nil,
1772+
"PostgreSQL adapter expects :modifiers to be a string or nil, got #{inspect(other)}"
1773+
)
17681774

17691775
defp options_expr(nil),
17701776
do: []

lib/ecto/migration.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,13 @@ defmodule Ecto.Migration do
479479
480480
To define a table in a migration, see `Ecto.Migration.table/2`.
481481
"""
482-
defstruct name: nil, prefix: nil, comment: nil, primary_key: true, engine: nil, options: nil, modifiers: nil
482+
defstruct name: nil,
483+
prefix: nil,
484+
comment: nil,
485+
primary_key: true,
486+
engine: nil,
487+
options: nil,
488+
modifiers: nil
483489

484490
@type t :: %__MODULE__{
485491
name: String.t(),

lib/ecto/migration/runner.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,12 @@ defmodule Ecto.Migration.Runner do
434434
defp command(ddl) when is_binary(ddl) or is_list(ddl),
435435
do: "execute #{inspect(ddl)}"
436436

437-
defp command({:create, %Table{modifiers: <<_::binary>>} = table, _}),
438-
do: "create #{render_modifiers(table.modifiers)} table #{quote_name(table.prefix, table.name)}"
439-
440437
defp command({:create, %Table{} = table, _}),
441-
do: "create table #{quote_name(table.prefix, table.name)}"
438+
do: "create #{table_modifiers(table.modifiers)} #{quote_name(table.prefix, table.name)}"
442439

443440
defp command({:create_if_not_exists, %Table{} = table, _}),
444-
do: "create table if not exists #{quote_name(table.prefix, table.name)}"
441+
do:
442+
"create #{table_modifiers(table.modifiers)} if not exists #{quote_name(table.prefix, table.name)}"
445443

446444
defp command({:alter, %Table{} = table, _}),
447445
do: "alter table #{quote_name(table.prefix, table.name)}"
@@ -506,5 +504,6 @@ defmodule Ecto.Migration.Runner do
506504
defp quote_name(name) when is_atom(name), do: quote_name(Atom.to_string(name))
507505
defp quote_name(name), do: name
508506

509-
defp render_modifiers(value), do: String.downcase(String.trim(value))
507+
defp table_modifiers(value) when is_binary(value), do: "#{value} table"
508+
defp table_modifiers(_), do: "table"
510509
end

test/ecto/migrator_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ defmodule Ecto.MigratorTest do
356356
end)
357357

358358
assert output =~ "== Running 13 Ecto.MigratorTest.CreateTableWithModifiersMigration.change/0"
359-
assert output =~ "create unlogged table sessions"
359+
assert output =~ ~r/create unlogged table sessions/i
360360
assert output =~ ~r"== Migrated 13 in \d.\ds"
361361
end
362362

0 commit comments

Comments
 (0)