Skip to content

Commit 8450566

Browse files
Don't add comment to removed columns (#545)
1 parent 50b2895 commit 8450566

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

lib/ecto/adapters/postgres/connection.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,9 @@ if Code.ensure_loaded?(Postgrex) do
13541354

13551355
defp comments_for_columns(table_name, columns) do
13561356
Enum.flat_map(columns, fn
1357+
{:remove, _column_name, _column_type, _opts} ->
1358+
[]
1359+
13571360
{_operation, column_name, _column_type, opts} ->
13581361
column_name = [table_name, ?. | quote_name(column_name)]
13591362
comments_on("COLUMN", column_name, opts[:comment])

test/ecto/adapters/postgres_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,11 @@ defmodule Ecto.Adapters.PostgresTest do
15801580
~s|COMMENT ON COLUMN "foo"."posts"."updated_at" IS 'column comment 2'|]
15811581
end
15821582

1583+
test "removing a column does not add a comment" do
1584+
alter = {:alter, table(:posts), [{:remove, :title, :string, [comment: "comment"]}]}
1585+
assert execute_ddl(alter) == [~s/ALTER TABLE "posts" DROP COLUMN "title"/]
1586+
end
1587+
15831588
test "create table with references" do
15841589
create = {:create, table(:posts),
15851590
[{:add, :id, :serial, [primary_key: true]},

0 commit comments

Comments
 (0)