Skip to content

Commit

Permalink
Don't add comment to removed columns (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski authored and josevalim committed Aug 21, 2023
1 parent b201ac2 commit 35c12f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ecto/adapters/postgres/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,9 @@ if Code.ensure_loaded?(Postgrex) do

defp comments_for_columns(table_name, columns) do
Enum.flat_map(columns, fn
{:remove, _column_name, _column_type, _opts} ->
[]

{_operation, column_name, _column_type, opts} ->
column_name = [table_name, ?. | quote_name(column_name)]
comments_on("COLUMN", column_name, opts[:comment])
Expand Down
5 changes: 5 additions & 0 deletions test/ecto/adapters/postgres_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,11 @@ defmodule Ecto.Adapters.PostgresTest do
~s|COMMENT ON COLUMN "foo"."posts"."updated_at" IS 'column comment 2'|]
end

test "removing a column does not add a comment" do
alter = {:alter, table(:posts), [{:remove, :title, :string, [comment: "comment"]}]}
assert execute_ddl(alter) == [~s/ALTER TABLE "posts" DROP COLUMN "title"/]
end

test "create table with references" do
create = {:create, table(:posts),
[{:add, :id, :serial, [primary_key: true]},
Expand Down

0 comments on commit 35c12f7

Please sign in to comment.