SAP-samples / btp-cap-multitenant-saas

Sample project that demonstrates how to setup a multitenant application for a Software-as-a-Service scenario, leveraging the Kyma and Cloud Foundry Runtimes of the SAP Business Technology Platform. Developers learn how to implement their own CAP (mtxs) based SaaS app including an SaaS API and integration with various essential SAP BTP service of...
Apache License 2.0
75 stars 38 forks source link

How to automatically switch service to access to shared table between HANA and SQLite? #10

Closed kaztakata closed 8 months ago

kaztakata commented 8 months ago

Dear team,

Thanks for your great contribution to share multitenancy application and instruction. I am implementing multitenancy application based on your repository and I have question for shared database container.

In your explanation, we need two CDS for both HANA for production and SQLite for local testing. Currently I extended your service to access to shared table and manually change CDS file /code/db/sqlite/data-model to /code/db/hana/data-model before deployment to Cloud Foundry.

Is there smarter way to switch between two CDS files? I could not find good example of this use case. So I am helpful if you advise me.

gregorwolf commented 8 months ago

Please check this example: fiori/package.json#L42

kaztakata commented 8 months ago

Hi @gregorwolf,

Thanks for your answer. That is helpful and I already checked this code sample.

But my question is how to refer to db CDS from service CDS. For example, when I want to add Shared entity to public-service.cds, now I am writing like below.

using {susaas.common as common} from '../../db/hana/data-model';
...
service PublicService @(path : '/catalog/PublicService', impl: 'srv/public-service') {

  entity Shared as projection on common.Shared
  ...

Hence I am specifying db/hana/ directory, I cannot use it in for local SQLite. How to automatically switch path in service CDS, or something alternatives?

alperdedeoglu commented 8 months ago

Hi Dear @kaztakata san, Thank you very much for your contribution! 

To be honest, when we designed this "common container" approach, I personally only considered the database layer usage. But your requirement is valid and makes sense. I think it might be useful for the rest of our valued susaas community members too.

I have a nice solution proposal for the problem you have. This solution proposal should not change the behavior of the repository and should also fix the problem you have.

The main reason we have two files is that Shared  entitys DB artifacts are already created on deployment; therefore, we would like to mention it to HANA to avoid errors, but for sqlite we ne need to create the tables.

Can you please confirm if the changes on the fix/cc-localdev branch fix the problem you have?

I also linked the relevant PR to this issue.

kaztakata commented 8 months ago

Hi @alperdedeoglu san,

Thanks for your solution. I think extend CDS is effective for this situation. I used your code and changed package.json to switch between production and development profiles like previous answer by Gregorwolf then working.