Skip to content

Commit c1bd4d6

Browse files
authored
Fix order of comment and after expressions (#480)
1 parent 389f855 commit c1bd4d6

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

integration_test/myxql/migrations_test.exs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ defmodule Ecto.Integration.MigrationsTest do
1515
end
1616
end
1717

18+
defmodule AlterMigration do
19+
use Ecto.Migration
20+
21+
def change do
22+
create table(:alter_table) do
23+
add(:column1, :string)
24+
end
25+
26+
alter table(:alter_table) do
27+
add(:column2, :string, after: :column1, comment: "second column")
28+
end
29+
end
30+
end
31+
1832
describe "Migrator" do
1933
@get_lock_command ~s[SELECT GET_LOCK('ecto_Ecto.Integration.PoolRepo', -1)]
2034
@release_lock_command ~s[SELECT RELEASE_LOCK('ecto_Ecto.Integration.PoolRepo')]
@@ -82,5 +96,16 @@ defmodule Ecto.Integration.MigrationsTest do
8296
refute down_log =~ @version_delete
8397
refute down_log =~ "commit []"
8498
end
99+
100+
test "add column with after and comment options" do
101+
num = @base_migration + System.unique_integer([:positive])
102+
103+
log =
104+
capture_log(fn ->
105+
Ecto.Migrator.up(PoolRepo, num, AlterMigration, log_migrations_sql: :info)
106+
end)
107+
108+
assert log =~ "ALTER TABLE `alter_table` ADD `column2` varchar(255) COMMENT 'second column' AFTER `column1`"
109+
end
85110
end
86111
end

lib/ecto/adapters/myxql/connection.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ if Code.ensure_loaded?(MyXQL) do
938938
after_column = Keyword.get(opts, :after)
939939
comment = Keyword.get(opts, :comment)
940940

941-
[default_expr(default), null_expr(null), after_expr(after_column), comment_expr(comment)]
941+
[default_expr(default), null_expr(null), comment_expr(comment), after_expr(after_column)]
942942
end
943943

944944
defp comment_expr(comment, create_table? \\ false)

0 commit comments

Comments
 (0)