Ash Elixir

AE

Ash Elixir

Join the community to ask questions about Ash Elixir and get answers from other members.

Join

support

showcase

today-i-learned

What's the correct approach to update an actor inside an action

In my system, I have an Accounts.User resource that is normally sent to actions as the actor (this is also the resource used in AshAuthentication, etc). I also have another API called Payments and inside of it, it has a resource Payments.Customer. Both Accounts.User and Payments.User uses the same table, the just have some unique fields to it (mostly Accounts.User has info about authentication like password, email, etc, and Payments.User info about Stripe customer id, payments methods, etc)....

Authentication failures

I am trying to debug authentication failures in a multi-node setup (load balanced not Elixir multi-node). I get session data written: "user" => "user?id=6a6ece18-0ede-4b81-a22a-73edc43db6a8" implying the authentication was sucessful, but the failure callback is being invoked in the auth controller. I presume this may be related to the web socket possibly happening before the session data is recorded from the live session? Any pointers on how to debug welcome....

How to assign a default value to existing rows via Ash.postgres generated migration code

When a non-null column is added, is there a way to specify a default value to assign to the new column for existing records? I believe in Ecto, it's done something like this, but I'm curious if this can be done through Ash DSL.
add :new_field, :string, default: "default value"
add :new_field, :string, default: "default value"
...

`mix doctor` shows errors for "struct spec" on resource modules

Hello. I'm getting errors in mix doctor on resource modules, like so... ``` --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Doc Cov Spec Cov Module File Functions No Docs No Specs Module Doc Struct Spec ... ...

Why store temporary sign in tokens and how to prune them?

Hey. ash_authentication with store_all_tokens? indeed stores all tokens, INCLUDING temporary sign in tokens when sign_in_tokens_enabled is enabled. First of all, I'm not sure if it's intended behavior. Why do we need to store a tmp token for sign in? Secondly, I can't find a way to prune it from my DB. I delete the actual token on user sign out, same way as ash_hq does, but I don't have access to that temporary token to delete it -> this leads to handing outdated records in tokens table....

Building an aggregates-only Resource

I'm building an admin dashboard that will display several aggregate data points sourced from different database tables. These data points should be available from a single AshGraphql query. How would you do this? I created a resource called Dashboard. My first approach was to create a calculation to calculate a data point. That wasn't going anywhere, so I defined an primary read action that loaded the data point from inside the prepare block. That's where I'm at so far. The problem is that calling read() on the API returns nil. Here is an example of the kind of data I want to expose:...

Is Ash well suited to Domain Driven Design

Hi everyone. First up, I'm new to Elixir and Ash and expect a steepish though enjoyable learning curve. 🤞 (I have lots of experience in other languages: Java, Go, Python, C#, VB :D, SQL etc.) I'm redesigning a complex solution that has ~8 "micro" services (mostly Go and Java), uses Drools (with dynamic code generation) for complex business rules, Apache Pulsar for messaging, Postgres databases, Angular SPA... In fact, it's TOO complex and unmanageable for a very small team, (1-2 ppl) and for various reasons the solution was never completed and released! I've been following DDD principles and have a good handle on the domains, actors, bounded contexts, messages/events etc....

Ecto.Multi like transactions

Hi Ash community, I'm looking to find some examples around how to bundle together database operations into one transaction. Like in Ecto.Multi. In practice I would like to do something like create or update operation where entry's existence is being checked before creation. In one transaction. ...

How to write complex query with fragments

I'm trying to write this query with Ash ``` select DATE(inserted_at), round(avg(percentage), 2) from coverage where "owner" = 'coverbot-io' and "repo" = 'coverbot' and is_for_default_branch...

Define order of code blocks being added to a migration

In my resource, I need to add a field that is generated automatically by postgres like this: ```elixir postgres do ......

attribute match constraints error message

When validating email format using regex, is there an easier way to show a more user friendly validation error message such as "invalid email format" rather than the default "must match the pattern ~r/[a-z...."? I believe it can be done inside action definition, but thought I might be missing an easier way to do the same in the attribute definition. ``` attribute :email, :ci_string do...

How to bypass ConfirmationHookChange in a specific action

In my resource, I set monitor_fields to be [:email]. Now I want to add an action that it "forcefully" change the user e-mail bypassing the whole confirmation process. Basically the idea is to use that function as an admin-only function....

How does AshAuthentication monitor_fields work?

I was looking into the confirmation addon for AshAuthentication and started wondering what is needed to make monitor_fields work. For example, I have that field set as monitor_fields: [:email] What exactly does that do? Does it "automagically" inserts a change on each action that can change the email field?...

Generic action has `api` nil in context when called from `code_interface`

I have a generic action in my resource: ```elixir action :blibs, :any do run fn _, context ->...

manage_relationship :remove across API's

I have a Tag resource that belongs in the Organization API, I have a Transaction resource that belongs in the Transactions API, there is a join resource between them called TransactionTag that is in the Transaction API registry. I am unable to manage_relationship :remove a Tag from a Transaction resource unless I also include the TransactionTag resource in the Organization registry. (I get a ResourceNotAllowed error otherwise) Is this expected behaviour? ...

Primary key as string (not UUID)

I have an existing table with a string key. In Ecto, this was generated in the changeset function. In the Ash documentation, there is only integer_primary_key(), and uuid_primary_key(). If I try leaving either of those out, it returns an error that says I need to specify a primary key. How can this be made to work?

How to determine API boundaries?

Hello, just wondering if I can get some guidance on how to think about APIs in Ash. I'm trying to add Ash to an existing application, and just not quite sure where to begin. Should I just start with a single API, focus on resources and break it out later? Curious to hear your thoughts.

Any examples of using can?

I'm trying to see if a user (actor) can perform an update action on target user. ``` iex(9)> MyApp.Users.can?({target_user, :update}, actor)
** (ArgumentError) Invalid action/query/changeset "nil"...

Simulating arguments on relationships with calculations

I've seen questions related to this come up in various forms pretty regularly over the last few months, and given the outcome of https://github.com/ash-project/ash/issues/375, I thought it might be helpful to collect a series of examples for common patterns in simulating parameterized relationships with calculations. Happy to turn the output of this into a patch to the docs for a new guide, or new section of the Calculations guide....