Skip to content

Add support for sorting direction in custom indexes #739

@andreh11

Description

@andreh11

Code of Conduct

  • I agree to follow this project's Code of Conduct

AI Policy

  • I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.

Is your feature request related to a problem? Please describe.

Hi! It's really easy to specifiy custom indexes (and statements) using AshPostgres, thanks! However, I'd also like to specify the sorting direction. I'm building an AuditLog resource, and in case a of compliance query, I'd like the logs to be already sorted by date, for example.

Describe the solution you'd like

We could specify the sorting direction like this:

custom_indexes do
  index desc: :occurred_at
  index [:action, [desc: :occurred_at]]
end

And it would generate the following Ecto migration:

create index(:events, [desc: :occured_at])
create index(:events, [:action, desc: :occured_at])

I guess we'd need to modify the index DSL and the type of fields would become something like atom | String.t | keyword | list(atom | String.t | keyword).

I've never hacked Ash before, but I might try to open a PR for this, if you want.

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions