question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multitenancy support

See original GitHub issue

SAP Cloud Platform CF offers the possibility to develop multitenancy applications and CAP has built in support.

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:open
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
austinkloske22commented, Apr 26, 2021

why don’t you put this in a PR? all contributions are welcome!

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.

0reactions
austinkloske22commented, Jan 14, 2022

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.

Screen Shot 2022-01-14 at 12 29 37 PM

Screen Shot 2022-01-14 at 12 30 50 PM

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found