From a5dbf0d2cbaf6ff745a7485ecc4b22e154db9bb1 Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Sat, 29 Jul 2023 23:00:51 -0400 Subject: [PATCH] don't add comment to removed columns --- 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 61c3237f..bf8a68e6 100644 --- a/lib/ecto/adapters/postgres/connection.ex +++ b/lib/ecto/adapters/postgres/connection.ex @@ -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]) diff --git a/test/ecto/adapters/postgres_test.exs b/test/ecto/adapters/postgres_test.exs index 5d0895dd..c66bb6ab 100644 --- a/test/ecto/adapters/postgres_test.exs +++ b/test/ecto/adapters/postgres_test.exs @@ -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]},