gjaldon / ecto_enum

Ecto extension to support enums in models
MIT License
563 stars 131 forks source link

Exception when running migration via distillery command #38

Closed harmon25 closed 7 years ago

harmon25 commented 7 years ago

Getting the following exception when running a migration via a distillery command.

Confirmed the oid referenced in the error message belongs to an enum type defined with ecto_enum residing in the pg_enum pg_catalog table

Appears the enum is being created, but when referenced in a schema the exception is raised. Any idea how to fix?

{"init terminating in do_boot",
{#{'__exception__'=>true,'
__struct__'=>'Elixir.RuntimeError',
message=><<"oid `58090` was not bootstrapped and lacks type information">>},
[{'Elixir.Ecto.Adapters.Postgres.Connection',prepare_execute,5,{file,"lib/ecto/adapters/postgres/connection.ex"},{line,86}]},
{'Elixir.Ecto.Adapters.SQL',sql_call,6,[{file,"lib/ecto/adapters/sql.ex"},{line,243}]},
{'Elixir.Ecto.Adapters.SQL',execute_and_cache,7,[{file,"lib/ecto/adapters/sql.ex"},{line,431}]},
{'Elixir.Ecto.Repo.Queryable',execute,5,[{file,"lib/ecto/repo/queryable.ex"},{line,130}]},
{'Elixir.Ecto.Repo.Queryable',all,4,[{file,"lib/ecto/repo/queryable.ex"},{line,35}]},
{'Elixir.Enum','-map/2-lists^map/1-0-',2,[{file,"lib/enum.ex"},{line,1229}]},
{elixir,erl_eval,3,[{file,"src/elixir.erl"},{line,224}]},
{elixir,eval_forms,4,[{file,"src/elixir.erl"},{line,212}]}]}}
init terminating in do_boot ()
harmon25 commented 7 years ago

looks familiar to this - https://github.com/elixir-ecto/postgrex/issues/248

harmon25 commented 7 years ago

figured it out - need to make sure to start and stop the repo before running the seed script that references enum types - the Repo module loads types on connection - so if not reconnecting after initial migration the oid reference to the custom type will be missing, as it was created after the connection.

schnittchen commented 7 years ago

This also happened to me during a data migration.

I tried to set an enum column value for all existing rows in a table in an ecto migration. Defaulting the column seemed like a bad idea because there is no sensible default going forward.

schnittchen commented 7 years ago

I found no way to safely stop and restart the repo during a migration.

schnittchen commented 7 years ago

Looks like https://github.com/elixir-ecto/postgrex/issues/243 is related

harmon25 commented 7 years ago

https://github.com/bitwalker/distillery/blob/master/docs/Running%20Migrations.md

I only have a single repo in my application - so by modifying the above to restart the Repo after migrations are complete will reload the newly generated OIDs.

It but does appear they may do something to fix this behaviour in newer postgrex release...

{:ok, pid} = App.Repo.start_link(pool_size: 1)

...Run Migration...

# stop repo
App.Repo.stop(pid)

# restart repo - only on repo start are OIDs loaded (currently) 
App.Repo.start_link(pool_size: 1)

... Run seeds ...