Ask A Question

Notifications

You’re not receiving notifications from this thread.

How Do I Create an App Where Each User Has A Separate Table

Vikram Sharma asked in Databases

Hi,

I want to create a web app which is a simple HR SaaS. Each user/company which registers will have get a separate table to upload list of employees. In terms of autorization a user/company can access only their table.

It is possible/advisible to take this approach in Rails i.e.

  1. A user can create their own table in database
  2. User can modify columns of the database

Thanks for the help.
Regards
Vikram

Reply

your SaaS app will have more than one table. Ex. Users table, Employees Table, Org Table. You mean you want a multi-tenant app where each companies data is separate from the others. Few ways to do this:

  1. one db for all your customers but scope via tentant_id or company_id etc
  2. one app but each customer gets their own db instance (expensive)
  3. postgres schema - if you use postgres as your db then you can have one db but separate schemas for each customer.

Gems you can use:

  1. https://github.com/influitive/apartment
  2. https://github.com/ErwinM/acts_as_tenant
  3. https://github.com/jekuno/milia

if you really want to learn how to build this you can also look at the following book: https://leanpub.com/multi-tenancy-rails

OR

check out Chris's video on the apartment gem (search in episodes)

Reply

Thanks for the help buddy.

Reply

For anyone interested this post talks about how to setup multi-tenancy using uuid's and not subdomains using postgresql.

http://andrewmarkle.com/2016/04/06/multitenancy-with-pundit/

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.