Can't load Postgrex custom types with Ecto 3.0

I’m migrating my project to phoenix 1.4 / ecto 3.0, but I’m currently stuck with a bunch of my models not compiling because of this error :

** (ArgumentError) invalid or unknown type Geo.Point for field :coordinates

It used to work with previous version of Ecto. I’m using following deps:

  • ecto 3.0.2
  • postgrex 0.14.0
  • geo 3.0.0
  • geo_postgis 2.1.0

I also defined custom types :

  [Geo.PostGIS.Extension, MyApp.Postgrex.Box2D] ++ Ecto.Adapters.Postgres.extensions(),
  json: Poison

that I’m referencing in my dev.exs file:

config :my_app, MyApp.Repo,
  types: MyApp.PostgresTypes

Any idea? Thanks!

1 Like

Where does Geo.Point come from? Looking at that code, Geo.Point is not implementing Ecto.Type behaviour which would explain the issue. Maybe you have some custom code or you’re using another package that does that? Could you prepare a minimal repo that compiles on Ecto 2.2 and doesn’t on 3.0?

1 Like

I guess that is the library presenting geo types as Ecto types.
I will work on a small example reproducing the issue, and let you know when ready

Gotcha. In your schemas do you have things like field :coords, Geo.Point or field :coords, Geo.PostGIS.Geometry? Looking at error message I’d guess you have the former but that shouldn’t work on ecto 2 either.

It was the former indeed! It’s compiling now using Geo.PostGis.Geometry (don’t know if it is really working, because I’m now having further compilation issues :wink: )

Thanks for your help, I’ll keep you posted when I’ll be able to run my tests.


Just finished my migration to Phoenix 1.4 / Ecto 3.0 (more painful than I expected, damn date_times …)
Everything related to my custom Geo types is working, thanks again!

How did you solve it?

Read @wojtekmach answer: replacing Geo.Point by Geo.PostGIS.Geometry did the trick for me

Where did you put your custom type?

[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Jason)

I set the code above into application/start

I put types: MyAPP.PostgresTypes

It’s not working…

** (Mix) The database for MyAPP.Repo couldn’t be dropped: connection not available and request was dropped from queue after 2

it returns connection not available…

Could you please share your settings ?

I created an extensions.ex file in my lib directory which contains

  [Geo.PostGIS.Extension, MyApp.Postgrex.Box2D] ++ Ecto.Adapters.Postgres.extensions(),
  json: Poison

Types are then referenced from config.exs as in my initial post

1 Like

This file only contains this piece of code?

Yep, nothing else
Maybe your error is not related to custom types?

Postgrex.Error) ERROR 58P01 (undefined_file) could not open extension control file “/usr/share/postgresq
l/11/extension/postgis.control”: No such file or directory

Sometimes it returns no connection… or postgis is invalid.

To me, it seems more related to postgis installation (or extension creation in your migrations)

Could you please show config.exs in the context of your comment " Types are then referenced from config.exs as in my initial post"?

I have switched from Geo.Point to Geo.PostGIS.Geometry but am getting:

Geo.PostGIS.Geometry.struct/1 is undefined, cannot expand struct Geo.PostGIS.Geometry. Make sure the struct name is correct

You can not use any of your own or your dependencies code in your configuration files.

Cheers I have got the app compiling using Geo.PostGIS.Geometry, but it seems so different from Geo.Point. I would rather just use Geo.Point but that seems impossible on the later versions of Ecto. I store latitude, longitude in my database.