HANA Cloud and deployments — SAP Guided Tutorial
Free sample lesson · open to everyone
Deploying a CAP app with SAP HANA Cloud: HDI containers, the db deployer module, MTA builds with mbt and cf deploy, secrets via bindings, and how to change the schema safely without losing data.
In this lessonShow sectionsHide sections
Visual overview
The situation: a real project scenario
A team renamed amount to netAmount in a CDS entity and redeployed to production. HDI recreated the table and the column's data was lost. They restored from backup, then re-did the change with @cds.persistence.journal on the entity and a migration rehearsal on a copy, which preserved the data.
Explanation
Getting a CAP app onto SAP BTP with a real database starts with adding the right facets: cds add hana switches the production profile to HANA, and cds add mta generates an mta.yaml describing the modules that make up the deployment — the service itself, a database deployer, and the various backing resources.
Each app gets its own HDI container, typically provisioned with the hdi-shared service plan, and a short-lived db-deployer module runs once per deployment to write the compiled tables and views from gen/db into that container before stopping.
mbt build -t ./mta_archives packages all of this into a single .mtar archive, and cf deploy mta_archives/<app>.mtar deploys it, creating and binding the resources it declares; cf apps, cf services, and the db-deployer's own logs are where you confirm it actually worked.
Schema evolution is the part that bites teams who treat HANA like a local SQLite file. Adding a new nullable column or a brand-new entity is safe and HDI handles it transparently. Changing a column's type or renaming it is not safe by default — HDI can recreate the underlying table, which silently drops the data in it.
The fix is to annotate the entity with @cds.persistence.journal, which causes CAP to generate an .hdbmigrationtable artifact so HDI performs an actual data migration instead of a drop-and-recreate.
Even with that annotation in place, it's worth rehearsing the change against a copy of production data before running it for real, since migrations can still behave unexpectedly on data shapes you didn't anticipate.
Secrets and environment-specific values follow the same discipline as everywhere else in CAP: credentials should come only from service bindings, never be hardcoded, and cds bind lets a developer connect to real cloud services locally without ever copying a secret into a config file.
Separate subaccounts or Cloud Foundry spaces for dev, test, and production, with one CI/CD pipeline promoting the same .mtar archive through all of them, keeps "it worked in test" meaningfully connected to "it will work in production" — building a different archive per environment undermines that guarantee. Differences between environments belong in .mtaext extension descriptors, not in separate builds.
To work through this directly: run cds add hana,xsuaa,mta, build with mbt, and deploy to a test space; read the db-deployer logs and locate the HDI container in the HANA database explorer; add a nullable field and redeploy, confirming the existing data survives; then change a field's type on a journaled entity and confirm the data is migrated rather than lost. The goal is to be able to redeploy with a schema change and prove, by row counts and spot checks, that nothing was lost in the process.
Code example
# add facets and deploycds add hana,xsuaa,mtanpm installmbt build -t ./mta_archivescf deploy mta_archives/bookshop_1.0.0.mtar // db/schema.cds — evolve with data in place@cds.persistence.journalentity Invoices : cuid { netAmount : Decimal(15,2); }Watch out
Common mistakes
- Deploying only the srv module and forgetting the db deployer.
- Renaming or retyping columns without a migration, silently losing data.
- Editing tables manually in the HDI container.
- Building a different archive per environment instead of promoting one artefact.
Do this
Best practices
- Promote one .mtar through environments with extension descriptors for differences.
- Use @cds.persistence.journal for entities whose schema will evolve with data in place.
- Check deployer logs and row counts after each production deployment.
In the interview
Interview angle
A deployment question should cover the MTA pieces (srv, db deployer, HDI, XSUAA), the build and deploy commands, and above all how you change schemas safely on live data and promote one artefact through environments.
Practice this lesson
Original educational case studies for SAP consultants, not official SAP certification exam questions. Verify product edition and implementation details against the current SAP documentation.
Quick check
0 of 4 questions attempted
Question 1 of 4
What does the db-deployer module in a CAP MTA do?
Question 2 of 4
You need to change a column type on a table that already holds production data. What is the CAP-supported approach?
Question 3 of 4
Which command creates the deployable archive from mta.yaml?
Question 4 of 4
How should a developer run locally against real HANA and XSUAA without copying secrets?
Practise this in an interview
Answer in your own words and get instant feedback, the way an interviewer would judge it.
1Walk me through deploying a CAP application with HANA Cloud to BTP Cloud Foundry.
2How do you change a CDS entity in production without losing data?
Was this lesson helpful?
Keep exploring
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.