Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:comment option causes an error when migrating remove/3 forward #544

Closed
jdav-dev opened this issue Jul 28, 2023 · 1 comment · Fixed by #545
Closed

:comment option causes an error when migrating remove/3 forward #544

jdav-dev opened this issue Jul 28, 2023 · 1 comment · Fixed by #545
Labels

Comments

@jdav-dev
Copy link

jdav-dev commented Jul 28, 2023

Elixir version

1.15.4

Database and Version

PostgreSQL 15

Ecto Versions

ecto 3.10.2, ecto_sql 3.10.1

Database Adapter and Versions (postgrex, myxql, etc)

postgrex 0.17.1

Current behavior

The :comment option does not work when migrating remove/3 forward. The migration attempts to apply the comment after dropping the column.

defmodule MyApp.Repo.Migrations.RemoveMyField do
  use Ecto.Migration

  def change do
    alter table(:my_table) do
      remove :my_field, :string, comment: "some comment"
    end
  end
end

When running this migration:

$ mix ecto.migrate --log-migrations-sql

11:49:45.322 [info] == Running 20230728152247 MyApp.Repo.Migrations.RemoveMyField.change/0 forward

11:49:45.322 [info] alter table my_table

11:49:45.324 [debug] QUERY OK db=0.9ms
ALTER TABLE "my_table" DROP COLUMN "my_field" []

11:49:45.326 [debug] QUERY ERROR db=1.7ms
COMMENT ON COLUMN "my_table"."my_field" IS 'some comment' []
** (Postgrex.Error) ERROR 42703 (undefined_column) column "my_field" of relation "my_table" does not exist
    (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:1005: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:327: Ecto.Migration.Runner.log_and_execute_ddl/3
    (elixir 1.15.4) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:290: Ecto.Migration.Runner.perform_operation/3
    (stdlib 5.0.2) timer.erl:270: :timer.tc/2

Expected behavior

The comment should not be applied when migrating remove/3 forward.

@jdav-dev jdav-dev changed the title :comment option does not work when migrating remove/3 forward :comment option causes an error when migrating remove/3 forward Jul 28, 2023
@jdav-dev
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant