Hi
I am not able to find the right way of generating and seeding multi-tenant (schema based) data for development.
There are 2 problems
- Generating data:
changeset_generator in Ash.Generator seems to be meant for testing data. Placing the generatpr code in “lib” folder makes the code unsafe in production. How can I use generator for dev data?
After the data is generated, how can I pass tenant/actor to insert that in database? Right now, I am bot able to read Users as the authorizer in App.Accounts.User is blocking the access to User.
- Seeding data:
If I use the priv/repo/seeds.exs for seeing data, how can I run it for multiple tenants? Like tenant_migrations are run for each tenant, is there is similar provision for tenant_seeds?
Thanks
You’d typically put this logic inside of test/support, i.e test/support/generator.ex, and then in your mix.exs you’d have something like:
def project do
[
...
elixirc_paths: elixirc_paths(Mix.env()),
...
]
end
# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
Indicating to compile the files in test/support during testing.
You can use the option authorize?: false when calling actions to bypass authorization. This can help with reading data during setup for example.
For running seeds, your best bet is to define a function in your test/support code that takes a tenant, and then call that with a tenant or tenants to set up data for specific tenants.