Can't load Postgrex custom types with Ecto 3.0

Where does Geo.Point come from? https://github.com/bryanjos/geo? 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 https://github.com/bryanjos/geo_postgis 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.

2 Likes

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?

Postgrex.Types.define(MyAPP.PostgresTypes,
[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
795ms

it returns connection not available…

Could you please share your settings ?

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

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

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

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.

Ah, we only use Geo.PostGIS.Geometry in the schema:

  schema "shops" do
    field :name, :string
    field :place_id, :string
    field :point, Geo.PostGIS.Geometry

and elsewhere is the app remains Geo.Point:

point: %Geo.Point{coordinates: {shop["longitude"], shop["latitude"]}, srid: 4326},

So it’s a small change after all, just important to make that distinction.