0

I have a multi-tenancy app where everything is stored in 1 Postgres database. All models have a account_id, so the data a customer can see is based on his account_id. This works perfect, but due to security and privacy concerns, customers demand that their data is stored in a separate database. So what do I need to do to make this happen? When a custome logs in, then you connect to its own database? And what is the best way to migrate the current data to the several customer databases?

I try appartment gem

  • 4
    If this is a demand then I would recommend moving away from multi-tenancy and charge the customers for siloed hosting. Just deploy the app to N locations, with N databases and charge for the individual hosting and db administration. When deploying you can just deploy to all sites. – engineersmnky Aug 18 '23 at 13:01
  • 2
    One database per customer might seem like a good idea now, but trust me, it will quickly become a living nightmare for you and your team and you will regret it. These become near impossible to maintain when you go beyond a trivial number of customers. Use a single database, and use *horizontal sharding*, a feature now part of Rails, to work at scale. – tadman Aug 18 '23 at 16:16

0 Answers0