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

Reload TYPE ENUM (Postgre) before migration #1080

Closed
esdrasedu opened this Issue Nov 12, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@esdrasedu

When you create migration with TYPE ENUM and try use ( in next migration), error is is triggered, because Postgres not find new TYPE ENUM.

If you call migration task again, error is NOT triggered, because Postgres load ENUM new .

Versions:
OS: Darwin 15.0.0
Postgre: 9.4.5
Elixir: 1.1.1
Erlang/OTP: 18
Ecto: 1.0.6
Postgrex 0.9.1

Sample

First

defmodule MyRepo.Migrations.CreateUserType do
  use Ecto.Migration

  def up do
    execute "CREATE TYPE user_status AS ENUM ('customer','admin')"

    alter table(:users) do
      add :status,    :user_status
    end
  end

  def down do
    execute "DROP TYPE user_status"
    alter table(:users) do
      remove :status
    end
  end
end

Second

defmodule MyRepo.Migrations.SeedUserType do
  use Ecto.Migration

  alias MyRepo.Repo
  alias MyRepo.User

  def up do
    Repo.update_all (from(u in User, where: u.parents < 0)), set: [status: "admin"]
  end

  def down do
    Repo.update_all User, set: [status: nil]
  end
end

Error

** (ArgumentError) no extension found for oid `29304`
    (postgrex) lib/postgrex/types.ex:280: Postgrex.Types.fetch!/2
    (postgrex) lib/postgrex/types.ex:213: Postgrex.Types.format/2
      (elixir) lib/enum.ex:1043: anonymous fn/3 in Enum.map/2
      (elixir) lib/enum.ex:1387: Enum."-reduce/3-lists^foldl/2-0-"/3
      (elixir) lib/enum.ex:1043: Enum.map/2
    (postgrex) lib/postgrex/protocol.ex:134: Postgrex.Protocol.message/3
    (postgrex) lib/postgrex/connection.ex:417: Postgrex.Connection.new_data/2
    (postgrex) lib/postgrex/connection.ex:292: Postgrex.Connection.handle_info/2

I think can having help for create type, or method for reload types enum, or after execute migrate reload types enum

@josevalim

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Nov 12, 2015

Member

Thank you for the report. We need to reload the types information correctly. :)

Member

josevalim commented Nov 12, 2015

Thank you for the report. We need to reload the types information correctly. :)

@josevalim josevalim added the Kind:Bug label Nov 28, 2015

@josevalim josevalim added this to the v2.0 milestone Nov 28, 2015

@josevalim

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Nov 28, 2015

Member

This is a postgres specific error due to the types cache. It also requires changes to the adapter API. At least the adapter API changes need to happen on 2.0.

Member

josevalim commented Nov 28, 2015

This is a postgres specific error due to the types cache. It also requires changes to the adapter API. At least the adapter API changes need to happen on 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment