Understand HDI container architecture, artifact types, safe vs unsafe schema changes, and the HDI deployer.
cds build produces deployable artifactsHDI is how CAP gets schema changes into HANA Cloud safely. Understanding the artifact lifecycle explains why some schema changes work silently and others fail with cryptic errors — knowing the rules means zero surprises at deployment time.
BTP CF Space
├── CAP Application (Node.js app) ← your service code
├── HDI Container service instance ← schema + data
└── HDI Deployer (one-off task) ← applies changes to HDI
@sap/hdi-deploy) that runs at deploy timeVCAP_SERVICES)cds build --for hana| CDS concept | Generated artifact | File extension |
|---|---|---|
entity |
Table | .hdbcds or .hdbtable |
| View / projection | Calculation view | .hdbcds |
| CDS function | Scalar function | .hdbfunction |
| Sequence | HDI sequence | .hdbsequence |
| Table data (CSV) | Table data | .hdbtabledata |
| Roles | HDI role | .hdbrole |
gen/db/
├── package.json ← HDI deployer entry point
└── src/
├── gen/
│ ├── my.bookshop.Books.hdbcds
│ ├── my.bookshop.Authors.hdbcds
│ └── my.bookshop.Orders.hdbcds
└── data/
└── my.bookshop-Books.hdbtabledata
// gen/db/package.json (generated by cds build)
{
"name": "bookshop-db",
"version": "1.0.0",
"dependencies": {
"@sap/hdi-deploy": "^4"
},
"scripts": {
"start": "node node_modules/@sap/hdi-deploy/deploy.js"
}
}
1. cf push bookshop-db (or mbt build + cf deploy)
2. HDI deployer starts
3. Compares current gen/db/src/ with what's in HDI
4. Determines delta (added, changed, removed artifacts)
5. Applies delta in dependency order
6. Exits 0 on success, non-zero on failure
7. CF task completes; CAP app now uses updated schema
✓ Add a new entity (table)
✓ Add a nullable column
✓ Add a new view
✓ Change a view definition
✓ Add an index
✗ Remove a column → HDI rejects by default
✗ Rename a column → treated as drop + add = data loss
✗ Change NOT NULL column → fails if existing rows have nulls
✗ Change column type → rejected if incompatible
-- For a rename: add new column, migrate data, deprecate old
ALTER TABLE BOOKS ADD (NEW_TITLE NVARCHAR(200));
UPDATE BOOKS SET NEW_TITLE = TITLE;
-- Then annotate old column @deprecated in CDS
# Nuclear option — drops and recreates the HDI container
# ALL DATA IS LOST
cds deploy --to hana --auto-undeploy
Only use on dev containers. Never on production.
// gen/db/src/roles/app_user.hdbrole
{
"role": {
"name": "app_user",
"schema_privileges": [{ "privileges": ["SELECT","INSERT","UPDATE","DELETE"] }]
}
}
HDI manages grants automatically for the app's technical user. You don't need to GRANT manually.
cds build --for hana and inspect gen/db/src/gen/ — find the .hdbcds filesnotes: String field to an entity and rebuild — verify the new artifact@deprecated annotation to a field instead of removing it@sap/hdi-deploy)cds build --for hana generates .hdbcds artifacts in gen/db/src/gen/--auto-undeploy resets the schema but destroys all data — dev only