type "citext" does not exist

wintermeyer
2023-01-29

wintermeyer:

During the “Integrating Ash Authentication and Phoenix” tutorial I get this migration:

create table(:users, primary_key: false) do
  add :id, :uuid, null: false, primary_key: true
  add :email, :citext, null: false
  #           ^^^^^^^
  add :hashed_password, :text, null: false
end

That results in the following error:

12:42:19.145 [info] create table users
** (Postgrex.Error) ERROR 42704 (undefined_object) type "citext" does not exist
    (ecto_sql 3.9.2) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1

https://hexdocs.pm/ash_postgres/AshPostgres.Repo.html says that I need to install the citext extension. But how do I do that?

There is the following example code but I don’t know where to put it.

wintermeyer:

I already tried that. Here’s is the code of lib/example/repo.ex :

wintermeyer:

defmodule Example.Repo do
  use AshPostgres.Repo, otp_app: :example

  def installed_extensions do
    ["pg_trgm", "uuid-ossp", "citext", "pg_stat_statements", "sslinfo"]
  end
end

wintermeyer:

Same error message:

13:08:15.950 [info] create table users
** (Postgrex.Error) ERROR 42704 (undefined_object) type "citext" does not exist
    (ecto_sql 3.9.2) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1

wln:

generate_migrations step should create an extension migration:

mix ash_postgres.generate_migrations Extension Migrations: * creating priv/resource_snapshots/extensions.json * creating priv/repo/migrations/20230129121708_install_citext_extension.exs

ZachDaniel:

This should be added to the getting started guide that if you are using ash_postgres you need to add that extension and generate migrations

wintermeyer:

Thanks! That did the trick.

wintermeyer:

I am currently rewriting the “Getting Started Ash Authentication Phoenix” tutorial. There are a bunch of challenges for newbies in the current documentation. It’s a bumpy road. But I am getting there.