I am learning to set up context-based multi-tenancy in my Phoenix app using Ash and AshPostgres. I have followed the instructions in the AshPostgres documentation (I believe) and I have created a new organization in the database. However, I get the error below when I try to run the migration command. I am not sure what I am doing wrong. Any help would be appreciated.
Running “mix ash_postgres.generate_migrations add_departments” worked just fine. There is a new department migration file in the “tenant_migrations” folder. It looks like what I expected.
❯ mix ash_postgres.migrate --tenants
11:30:10.106 [debug] QUERY OK source="organizations" db=4.8ms decode=0.8ms queue=0.4ms idle=14.0ms
SELECT o0."id", o0."name", o0."domain", o0."go_live_date", o0."is_live", o0."email_domains", o0."inserted_at", o0."updated_at" FROM "organizations" AS o0 []
↳ anonymous fn/3 in AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:704
** (Protocol.UndefinedError) protocol Enumerable not implemented for {:ok, [#MyAshPhoenixApp.Client.Organization<__meta__: #Ecto.Schema.Metadata<:loaded, "organizations">, id: "68833194-f310-4af8-a7cd-5f3f23c3ece7", name: "default", domain: "default", go_live_date: nil, is_live: false, email_domains: [], inserted_at: ~U[2024-04-26 17:37:39.483530Z], updated_at: ~U[2024-04-26 17:37:39.483530Z], aggregates: %{}, calculations: %{}, ...>]} of type Tuple. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Stream, StreamData
(elixir 1.16.2) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir 1.16.2) lib/enum.ex:166: Enumerable.reduce/3
(elixir 1.16.2) lib/enum.ex:4396: Enum.map/2
(ash_postgres 2.0.0-rc.11) lib/mix/helpers.ex:125: AshPostgres.Mix.Helpers.tenants/2
(ash_postgres 2.0.0-rc.11) lib/mix/tasks/ash_postgres.migrate.ex:121: anonymous fn/3 in Mix.Tasks.AshPostgres.Migrate.run/1
(ecto_sql 3.11.1) lib/ecto/migrator.ex:170: Ecto.Migrator.with_repo/3
(elixir 1.16.2) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
(mix 1.16.2) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
Here are two gist files for my Organization and Department:
organization.ex gist
department.ex gist