Configuring Ash Repo w/PetalPro: One Repo or Two?

I’m working on an application that uses the PetalPro framework for things like user management, authentication, and event logging which uses the standard Ecto methods for CRUD manipulations in LiveView to the database. (Would be great if it were Ash aware, but that feature doesn’t have enough “votes” yet). The parts that I’m adding for my app do use Ash and I’m confused as to the best approach to configure repos. Currently, I have two repo.ex modules (one for Ecto and one for Ash) but I’m thinking it might be better to have only one child process and be able to talk through that using either Ash or conventional Ecto querying techniques. The AshPostgres documentation says “it’s just a thin wrapper” and “you can use init” to do this (I think) but am not sure if I should do this or how exactly to get this working. Thoughts on best approach and how to do would be helpful. Thank you.

There should be no issues if you use a single repo configured with use AshPostgres.Repo :slight_smile:

That is basically

use Ecto.Repo, adapter: ....

plus some additional functions. Other things should be able to use it as an ecto repo just fine.

Sorry to be dense but I’m still confused. here is my AshRepo.ex (see below). Are you saying that all I need to add another use Ecto.Repo, adapter: ... line inside there or perhaps something else? Assuming so, then I suppose I would set :ash_repo in application.ex and configure it further in config.exs and then be sure that both the PetalPro modules that talk pure Ecto and the Ash resources are aliasing in the same MyApp.Ash.Repo module? Appreciate the help.

defmodule MyApp.Ash.Repo do
   use AshPostgres.Repo, otp_app: :ash_repo
   use PetalFramework.Extensions.Ecto.RepoExt

   def installed_extensions do
     ["uuid-ossp", "citext"]

Update: I figured it out. All I had to do was be use that both the Ash resource modules and the PetalPro modules aliased in the same MyApp.Repo module, which is the one with use AshPostgres.Repo inside. Works like a charm.

1 Like