cancel
Showing results for 
Search instead for 
Did you mean: 

Cloud MTA Build Tool, Cloud Application Programming Model and db.kind sql

SebastianEsch
Active Participant

Hi,

I noticed that in a CAP application where I set the db.kind to sql in order to test it locally with sqlite and to use HANA when I deploy the MTA application to Cloud Foundry, CAP handles the in May with cds@3.34.2 introduced db.kind sql as expected.

But the Cloud MTA Build Tool does not generate the database application in gen/db when the db.kind in package.json is not hana. It is quite cumbersome to change the package.json every time you switch between cds watch and mbt build for deployment.

My mbt version is 1.0.15. The output from the mbt build -t ./ command is:

...
[cds] - Determining CDS build tasks from CDS configuration - applying defaults
[cds] - Determining database kind.
[cds] - Found sqlite database - skipping HANA build task
[cds] - Determining implementation technology
[cds] - Found implementation technology node
[cds] - Determining fiori modules - matching modules */webapp/manifest.json
[cds] - Found fiori app paths [app]
[cds] - Determining single or multi-tenant strategy.
[cds] - No CDS custom build tasks defined for project [/Users/***].
[cds] - The following build tasks have been auto-created and will be executed.
[cds] - You may want to add them to .cdsrc.json or package.json of your project and customize to your needs if required.
{
  "build": {
    "target": "gen",
    "tasks": [
      {"src":"srv","for":"node-cf","options":{"model":["db","srv","app"]}},
      {"src":"app","for":"fiori","options":{"model":["db","srv","app"]}}
    ]
  }
}
...
[2020-07-24 18:42:30]  INFO validating the MTA project
[2020-07-24 18:42:30] ERROR the "mta.yaml" file is not valid: 
line 61: the "gen/db" path of the "db" module does not exist
make: *** [validate] Error 1
Error: could not build the MTA project: could not execute the "make -f Makefile_20200724184218.mta p=cf mtar= strict=true mode= t=\"./\"" command: exit status 2

Is there a plan to make the mbt tool aware of the new CAP options regarding HANA and sqlite? And if yes, is there a timeline?

Kind regards,

Sebastian

SebastianEsch
Active Participant
0 Kudos

The problem is not that I cannot use environments or switch environments in the cds commands. It's ok as a workaround.

My underlying question is: when does mbt learn to understand the new "sql" value for db.kind in CAP?

Do I need to raise an issue on Github? CAP is in the process of moving from Github Issues to here for feedback, I guess mbt still works with Github issues?

Accepted Solutions (0)

Answers (2)

Answers (2)

chgeo
Advisor
Advisor

With the upcoming July release for CAP, you can use --production in all cds commands to active the production profile, e.g

cds build --production

You might change your mta.yaml to contain this switch when calling cds build.

jhodel18
Active Contributor
0 Kudos

Hi Christian,

Thanks for letting us know this useful update!

But how about an option to add —auto-undeploy? I’ve been doing this manually every time there’s a deployment error relating to new Hana db artifacts.

chgeo
Advisor
Advisor

Hi.. this seems to be a whole new topic. Please consider opening a separate question.

jhodel18
Active Contributor

Hi Sebastian,

There's a concept of "profiles" in CAP -- see below documentation:

https://cap.cloud.sap/docs/advanced/config#profiles

You don't have to change the CDS configuration if you set your profiles correctly. For my own setup, I have the default (or no profile) config to point as local testing. and then I have "production" profile for SCP scenario.

SebastianEsch
Active Participant
0 Kudos

Hi Jhodel,

can you share how you setup your package.json and .cdsrc.json? Are you using the mbt tool to build your MTAR?

package.json takes precedence over .cdsrc.json - so when I define my setup as follows:

.cdsrc.json

{
    "requires": {
        "db": {
            "kind": "sqlite"
        }
    },
    "[production]": {
        "requires": {
            "db": {
                "kind": "hana"
            }
        }
    }
}

I need to remove the requires.db section from package.json. Otherwise the settings from package.json take precedence.

But when I remove the required.db section from package.json, the mbt build breaks again. The mbt build at the moment works for me only if I specify required.db.kind=hana in package.json. And then I can't use cds watch with sqlite locally.

My impression is, that the mbt build tool is not yet aware of the new db.kind=sql option in CAP.

Kind regards,

Sebastian

jhodel18
Active Contributor
0 Kudos

Hi Sebastian,

My setup is a bit complicated because I'm using multiple external services. Anyway, if I simplify my configuration, it actually matches the config you mentioned above (with the exception of using sql instead of sqlite). Note that I'm using package.json mainly for CDS configuration.

If you configured your setting this way:

{
    "requires": {
        "db": {
            "kind": "sql"
        }
    },
    "[production]": {
        "requires": {
            "db": {
                "kind": "hana"
            }
        }
    }
}

You would need to make sure that you start your service according to your needs during runtime execution. If you are testing using SQL.

If I want to test using sql (in-memory) db, then the command to execute is:

> cds watch

If I want to test using hana db then use:

> NODE_ENV=production cds watch

Note that I'm using macOS hence my command is NODE_ENV=production. And yes, I am using MBT tool for MTAR build, and I created an npm script for the build which calls the same command for setting the environment variable:

NODE_ENV=production mbt build

With this approach, I don't need to change my configuration. I just need to change the way I start or build my project.

SebastianEsch
Active Participant
0 Kudos

Hi Jhodel,

ok, now I understand and was able to make your approach work.

If you setup the db configuration in .cdsrc.json as you mentioned above and remove it from package.json, switching the environments works. The different environments do not work when you try to define them in package.json.

Actually the mbt build tool automatically uses the production environment for the MTAR build.

With the following setup:

package.json

{
    "name": "mbt-build-sql",
    "version": "1.0.0",
    "description": "A simple CAP project.",
    "repository": "<Add your repository here>",
    "license": "UNLICENSED",
    "private": true,
    "dependencies": {
        "@sap/cds": "^3",
        "express": "^4",
        "@sap/hana-client": "^2.4.177"
    },
    "scripts": {
        "start": "npx cds run"
    }
}

.cdsrc.json

{
    "cds": {
        "requires": {
            "db": {
                "kind": "sqlite" // or sql, does not matter has the same effect
            }
        },
        "[production]": {
            "requires": {
                "db": {
                    "kind": "hana"
                }
            }
        }
    }
}

I can successfully start the CAP application locally with a sqlite database:

cds watch

Build the MTA file with the HANA application:

mbt build -t ./

Using two different environments in CAP for me is a workaround that defats the purpose of the new sql db.kind. I would expect the mbt build tool to understand the "new" database option sql in addition to sqlite and hana. My impression is that the cds tool introduced the new feature to make life easier, but the mbt tool has still to catch up.

Kind regards,

Sebastian

jhodel18
Active Contributor
0 Kudos

It sounds odd to me that the environments doesn’t work for you if you put the config in package.json. This is exactly what I use. Anyway, good to know that it is working for you now.