How to create a partial index with Ash?

Eduardo B. Alexandre
2023-02-15

Eduardo B. Alexandre:

I was wondering, can I create a partial index using identities or some other way with Ash or should I just write a migration manually directly?

For example, how can I do this partial index?

create index(:users, [:id], where: "not \"invalid_token?\"", name: :users_valid_tokens)

ZachDaniel:

You can do it with custom_indexes 😄

ZachDaniel:

that top result

Eduardo B. Alexandre:

Sorry, I was trying to search the docs with the partial word 😅

ZachDaniel:

would go inside the postgres section, like:

postgres do
  custom_indexes do
    custom_index ...
  end
end

ZachDaniel:

no worries 😄 I think its on us to include common search terms in the docs for things

ZachDaniel:

so that people can find it better when searching 😄

Eduardo B. Alexandre:

And I guess if I want to make the changeset aware of that index I need to use check_constrains right?

ZachDaniel:

nope, it will be aware of that index 🙂

Eduardo B. Alexandre:

Nice!