How can I tell identities
to either be case sensitive or not? What is the switch? Here’s an example where I want the identity to not be case sensitive.
attributes do
uuid_primary_key :id
attribute :email, :string do
allow_nil? false
end
end
identities do
identity :unique_email, [:email]
end
Is using Ash.Type.CiString
the best way to achieve this or can I do it in the identities
?
2 Likes
You would want to use the :ci_string
type on the :email
attribute instead of regular :string
so that it ignores the case.
The out of the box Ash.Type’s are documented here.
The database in the migrations Ash generates will also use the appropriate type in those case ignore string attributes, so that the database identity constraint (a unique index) is enforced which ignores the case also.
Ash will also ensure that when using Postgres that the CITEXT extension is loaded within the migration.
UPDATE: I forgot to mention you need to ensure /lib/myapp/repo.ex
specifies the extensions you need:
defmodule MyApp.Repo do
use AshPostgres.Repo, otp_app: :myapp
def installed_extensions do
["citext"]
end
end
3 Likes