type "citext" does not exist

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
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
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.
5 Replies
Lee N
Lee N3y ago
GitHub
ash_hq/repo.ex at main · ash-project/ash_hq
The Ash Framework homepage and documentation site. - ash_hq/repo.ex at main · ash-project/ash_hq
Stefan Wintermeyer
I already tried that. Here's is the code of lib/example/repo.ex:
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
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
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
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
Lee N
Lee N3y ago
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
mix ash_postgres.generate_migrations

Extension Migrations:
* creating priv/resource_snapshots/extensions.json
* creating priv/repo/migrations/20230129121708_install_citext_extension.exs
ZachDaniel
ZachDaniel3y ago
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
Stefan Wintermeyer
Thanks! That did the trick. 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.

Did you find this page helpful?