javascriptpostgresqlsails.jsmulti-tenantsails-postgresql

Sails.js - Postgresql Adapter multiple schemas


I've been searching a lot about Sails.js multi tenancy capabilities and I know that such a feature is not yet implemented. My initial idea was to build multi tenant app by creating one database per tenant.

Since I realized that I can't do such a thing in Sails.js yet, I tried a different aproach by creating only one database ( POSTGRES ) but with lots of schemas, each one representing a tenant. My problem is that I can't/I dunno ( don't even know if that is possible in Sails/Postgres adapter ) how to dynamically ( on runtime ) define what schema a given object should query aganist, based on the logged user.

Has anyone faced a problem like this? How can I proceed?

Sorry for English and thanks.


Solution

  • In my experience adding in the model does not work. The only thing that worked for me was using the meta call to specify the schema.

    await Users.create(newUser).meta({ schemaName: 'admin' });

    A bit cumbersome, but it is working.

    Hope this helps someone.