Example of Phoenix application with database multi-tenancy.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.images
assets
config
lib
priv
test
.credo.exs
.dockerignore
.editorconfig
.formatter.exs
.gitignore
.tool-versions
CODE_OF_CONDUCT.md
Dockerfile
LICENSE
README.md
docker-compose.yml
mix.exs
mix.lock

README.md

MultiTenancex

CircleCI

Example of Phoenix application with database multi-tenancy. A practical way to see the concepts tackled in this post from my website.

Images

Home Home.

Login Login.

Admin Dashboard Admin Dashboard.

Admin Product Index Admin Product Index.

Admin Product New Admin Product New.

Company Home Company Home.

Example data

There's a user in the seeds to use for testing purposes:

Special database multi-tenant mix tasks

If you want to create some migration for every tenant:

> docker-compose run multi_tenancex mix multi_tenancex.gen.tenant_migration create_some_table

If you want to migrate the migrations for every tenant:

> docker-compose run multi_tenancex mix multi_tenancex.ecto.migrate_tenants

If you want to rollback the migrations for every tenant:

> docker-compose run multi_tenancex mix multi_tenancex.ecto.rollback_tenants

Setup development environment with Docker

This project is Docker friendly from day one. To start working on it:

  • Setup the multi_tenancex container with docker-compose build multi_tenancex.
  • Install dependencies with docker-compose run multi_tenancex mix deps.get.
  • Create your database with docker-compose run multi_tenancex mix ecto.create.
  • Migrate your database with docker-compose run multi_tenancex mix ecto.migrate.
  • Run seeds for default data with docker-compose run multi_tenancex mix run priv/repo/seeds.exs.
  • Install Node.js dependencies with docker-compose run multi_tenancex bash -c "cd assets; npm install".
  • Start the application with docker-compose up

Setup testing environment with Docker

This step assumes you already followed instructions from previous paragraph.

  • Create your testing database with docker-compose run multi_tenancex env MIX_ENV=test mix ecto.create.
  • Migrate your testing database with docker-compose run multi_tenancex env MIX_ENV=test mix ecto.migrate.
  • Run the test suite with docker-compose run multi_tenancex env MIX_ENV=test mix test.
  • Run the test suite with coverage report on cover folder with: docker-compose run multi_tenancex env MIX_ENV=test mix coveralls.html.

This project was developed by dreamingechoes. It adheres to its code of conduct and contributing guidelines, and uses an equivalent license.