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 Jul 30, 2023
1 parent 50b2895 commit 8450566
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 @@ -1354,6 +1354,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 @@ -1580,6 +1580,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 8450566

Please sign in to comment.