Apartmentex

Easy SaaS for Phoenix/Ecto.

*Tenant-qualified queries targeting postgres schemas or MySql databases *Automatic migrations for tenant tables to schema for Postgres or database for MySQL

See an example app at https://github.com/Dania02525/widget_saas

Setup

{:apartmentex, github: "Dania02525/apartmentex"}
config :apartmentex, schema_prefix: "prefix_" # the default prefix is "tenant_"

Use

Place tenant only migrations in a new folder in priv/repo called "tenant_migrations". These migrations should use Apartmentex.Migration, not Ecto.Migration.

You can now add a new tenant and automatically create a new schema for Postgres users or a new database for MySQL users, and run the migrations in priv/repo/tenant_migrations for that schema or database.

Table references and indexes in a migration will be applied to the same tenant prefix as the table within tenant_migrations.

Apartmentex.new_tenant(Repo, tenant)

When deleting a tenant, you can also automatically drop their associated schema or database (for MySQL).

Apartmentex.drop_tenant(Repo, tenant)

Include the tenant struct or tenant id in Apartmentex calls for queries, inserts, updates, and deletes.

widgets = Apartmentex.all(Repo, Widget, tenant)
Apartmentex.insert(Repo, changeset, tenant)
Apartmentex.update(Repo, changeset, tenant_id)
Apartmentex.delete!(Repo, widget, tenant_id)

To Do