Apartmentex

Easy SaaS for Phoenix/Ecto.

NOTE Use this version if adding this to project using Ecto version at or above 1.1.0 and below 2.0

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

Setup

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