Triplex v1.1.2 Triplex View Source
This is the main module of Triplex.
The main objetive of it is to make a little bit easier to manage tenants through postgres db schemas or equivalents, executing queries and commands inside and outside the tenant without much boilerplate code.
Using the tenant
This module has useful functions to manage your tenants, like create/1
,
rename/2
and drop/1
, but if you’re trying to apply the tenant to a
query, changeset or schema, stay with your application Repo
, sending the
prefix. Like this:
Repo.all(User, prefix: Triplex.to_prefix("my_tenant"))
It’s a good idea to call Triplex.to_prefix
on your tenant name, altough is
not required. Because, if you configured a tenant_prefix
, this function will
return the prefixed one.
Link to this section Summary
Functions
Returns all the tenants on the given repo
Returns a %Triplex.Config{}
struct with all the args loaded from the app
configuration
Creates the given tenant on the given repo
Creates the tenant schema/database on the given repo
Drops the given tenant on the given repo
Returns if the tenant exists or not on the given repo
Migrates the given tenant on your repo
Return the path for your tenant migrations
Renames the given tenant on the given repo
Returns if the given tenant is reserved or not
Returns the list of reserverd tenants
Returns the value of the configured tenant field on the given map
Returns the tenant name with the given prefix
Link to this section Functions
Returns all the tenants on the given repo.
The function to_prefix/1
will be applied to the tenant.
If the repo is not given, it uses the one you configured.
Returns a %Triplex.Config{}
struct with all the args loaded from the app
configuration.
Creates the given tenant on the given repo.
Besides creating the database itself, this function also loads their
structure executing all migrations from inside
priv/YOUR_REPO/tenant_migrations
folder.
If the repo is not given, it uses the one you configured.
Creates the tenant schema/database on the given repo.
After creating it successfully, the given function callback is called with the tenant and the repo as arguments.
The function to_prefix/1
will be applied to the tenant.
If the repo is not given, it uses the one you configured.
Drops the given tenant on the given repo.
The function to_prefix/1
will be applied to the tenant.
If the repo is not given, it uses the one you configured.
Returns if the tenant exists or not on the given repo.
The function to_prefix/1
will be applied to the tenant.
If the repo is not given, it uses the one you configured.
Migrates the given tenant on your repo.
The function to_prefix/1
will be applied to the tenant.
If the repo
is not given, it uses the one you configured.
Return the path for your tenant migrations.
If the repo
is not given, it uses the one you configured.
Renames the given tenant on the given repo.
If the repo is not given, it uses the one you configured.
Returns if the given tenant is reserved or not.
The function to_prefix/1
will be applied to the tenant.
Returns the list of reserverd tenants.
By default, there are some limitations for the name of a tenant depending on the database, like “public” or anything that start with “pg_”.
You also can configure your own reserved tenant names if you want with:
config :triplex, reserved_tenants: ["www", "api", ~r/^db+$/]
Notice that you can use regexes, and they will be applied to the tenant names.
Returns the value of the configured tenant field on the given map.
Returns the tenant name with the given prefix.
If the prefix is omitted, the tenant_prefix
configuration will be used.
The tenant can be a string, a map or a struct. For a string it will
be used as the tenant name to concat the prefix. For a map or a struct, it
will get the tenant_field/0
from it to concat the prefix.