Skip to content

Commit cc6929d

Browse files
authored
docs: add example all_tenants implementation (#548)
1 parent 4651aa6 commit cc6929d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

documentation/topics/advanced/schema-based-multitenancy.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ The generated migrations include a lot of niceties around multitenancy. Specific
1010

1111
Migrations in the tenant directory will call `repo().all_tenants()`, which is a callback you will need to implement in your repo that should return a list of all schemas that need to be migrated.
1212

13+
For example, if you use the `manage_tenant` directive described below, you could do:
14+
15+
```elixir
16+
defmodule Myapp.Repo do
17+
use AshPostgres.Repo, ...
18+
19+
import Ecto.Query, only: [from: 2]
20+
21+
...
22+
23+
def all_tenants do
24+
all(from(row in "organizations", select: fragment("? || ?", "org_", row.id)))
25+
end
26+
end
27+
```
28+
1329
## Automatically managing tenants
1430

1531
By setting the `template` configuration, in the `manage_tenant` section, you can cause the creation/updating of a given resource to create/rename tenants. For example:

0 commit comments

Comments
 (0)