From 35c12f7c04cd741cdab1701055475d5b315378bd Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Sun, 30 Jul 2023 08:40:56 -0400 Subject: [PATCH] Don't add comment to removed columns (#545) --- lib/ecto/adapters/postgres/connection.ex | 3 +++ test/ecto/adapters/postgres_test.exs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/ecto/adapters/postgres/connection.ex b/lib/ecto/adapters/postgres/connection.ex index 28e57235..e28184d6 100644 --- a/lib/ecto/adapters/postgres/connection.ex +++ b/lib/ecto/adapters/postgres/connection.ex @@ -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]) diff --git a/test/ecto/adapters/postgres_test.exs b/test/ecto/adapters/postgres_test.exs index 5c4af27e..ab2685cb 100644 --- a/test/ecto/adapters/postgres_test.exs +++ b/test/ecto/adapters/postgres_test.exs @@ -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]},