Multitenancy support
See original GitHub issueSAP Cloud Platform CF offers the possibility to develop multitenancy applications and CAP has built in support.
- https://cap.cloud.sap/docs/guides/multitenancy#how-it-works
- https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/5e8a2b74e4f2442b8257c850ed912f48.html
- https://blogs.sap.com/2020/08/20/getting-your-head-into-cloud-application-programming-model-multitenancy/
When running on SAP CF, the PostgreSQL adapter should be able to handle the multitenancy. I am currently not sure about all the requirements, but one is to change the schema based on the requests tenant. A possible solution could like this:
class PostgresDatabase extends cds.DatabaseService {
...
async acquire(arg) {
// fetch the tenant if available
const tenant = (typeof arg === 'string' ? arg : arg.user.tenant) || 'anonymous'
// define the used schema, maybe add some more advanced naming logic
const schema = tenant === 'anonymous' ? 'public' : tenant;
// change the PostgreSQL schema for the client
this._pool.on('connect', (client) => {
// search_path also supports naming multiple schemas so things can be split across schemas (provider, subscribers)
client.query(`SET search_path TO ${schema};`)
})
const dbc = await this._pool.connect()
return dbc
}
...
}
For a future implementation it would be necessary to identify all the internal requirements by analyzing the cds core and come up with a concept for PostgreSQL (that maybe works for other DB adapters as well).
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
SaaS: Single Tenant vs Multi-Tenant - What's the Difference?
Multi-Tenant – Multi-tenancy means that a single instance of the software and its supporting infrastructure serves multiple customers.
Read more >Multitenancy - Wikipedia
Software multitenancy is a software architecture in which a single instance of software runs on a server and serves multiple tenants.
Read more >What is multi-tenancy? | Definition from TechTarget
Multi-tenancy is an architecture in which a single instance of a software application serves multiple customers. Each customer is called a tenant. Tenants...
Read more >Multi-tenancy support (optional) - IBM
Multi-tenancy support (optional) · 1 Single or multiple MQ backbones for high-speed, component-to-component communication · 2 Single or multiple ICFM engine ...
Read more >Multi-Tenancy (Multi-Company) Support - Micro Focus
Multi-Tenancy (Multi-Company) Support. Multi-tenancy is when a single instance of software runs on a server, serving multiple client organizations (also ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
1st open source PR created! https://github.com/sapmentors/cds-pg/pull/113 - Please let me know if I need to do anything differently next time.
I think that multitenant support will need to be implemented in the cds-dbm module.
I would like to add a multitenant flag and tenant array in the migration options. If the multitenant flag = true, then we also deploy to tenant schemas. Problem is I don’t know how to proberly implement & test this feature yet.