graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.49k stars 568 forks source link

multi tenancy and update pg schema without restart #2074

Closed mariel-sendblocks closed 4 weeks ago

mariel-sendblocks commented 1 month ago

Hey, I have a SAAS service that support multiple tenants. Each tenant can create its own namespace for some business unit and in that namespace he can create many entities (tables..).

A few questions:

  1. Sounds like the best alternative for me is having a dedicated db per tenant (same postgresql instance) and have a dedicated postgraphile instance per tenant. Is there any other good alternative ?
  2. When a tenant creates a new business unit I would like to create a new pg schema for him. I would like to add that new schema to the existing schemas that are monitored with the watch feature. Is there a way to do it without restarting the postgraphile service ?
benjie commented 4 weeks ago
  1. keeping them in the same schema but using a naming convention could also work (e.g. prefix with 27_ for user 27's tables.
  2. Maybe; grafserv has a setPreset method you could call to pass through a new preset that includes the new schema configuration. I've not tried it. Alternatively you could just close down the old postgraphile instance (in memory) and create a new one (in memory) without restarting the process.