Where to call Postgrex.Types.define in Phoenix/Ecto project?

Hey! I’m trying to get Geo’s Postgis extensions loading on a phoenix project but am getting confused with where to call
Phoenix.Types.define within my configuration and loading code. Can anyone provide any guidance on where best to do this within a Phoenix app?

Cheers!

2 Likes

I’m doing it like this

config/config.exs

use Mix.Config

config :test, ecto_repos: [Test.Repo]

config :test, Test.Repo,
  types: Test.PostgrexTypes

import_config "#{Mix.env}.exs"

lib/test/postgrex_types.ex

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

But it’s an umbrella app. I don’t think it would be much different in a phoenix app. There I would also place postgrex_types.ex somewhere in lib.

6 Likes

Thanks!