cds-dbm
A delta deployment and migration tool for CAP on PostgreSQL that diffs the live schema against a reference schema with Liquibase and applies the change, never dropping tables by default.
cds-dbm deploys a CAP data model to PostgreSQLPostgreSQLA relational database. For CAP it is the production database when the answer is not HANA, reached through an adapter that translates CDS queries into its SQL. as a delta, for relational databases other than the SAP HANA and SQLite that @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, cap supported natively when it was written. It clones the running schema, deploys the full model into a separate reference schema, has Liquibase diff the two, adjusts the changelog for undeployment and ordering, and applies it to the live schema. Tables are never dropped by default. An undeploy.json lists the ones to remove, or the auto-undeploy flag removes every table and view the model does not know. Beside deploy it has diff, drop and load. Load has a delta mode that updates CSV records by key and leaves the rest of the table alone, where @sap/cds only truncates and inserts. A cds build task produces a deployer for PostgreSQL on SAP BTP Cloud Foundry. Liquibase is Java, so the machine running it needs a JRE 8 or later. PostgreSQL through cds-pgcds-pgA PostgreSQL adapter for SAP CDS, built by the SAP Mentors community, which gave CAP a Postgres persistence option years before @cap-js/postgres shipped.independent, cap is the only database it supports, and SAP HANA is left to @sap/hdi-deploy. From @sap/cds 7, PostgreSQL is supported natively through @cap-js/postgres@cap-js/postgresThe PostgreSQL database service — the production option for running CAP off HANA, sharing the base service with the other three.sap official, cap, and the repository was archived in July 2023.
Facts
Where it sits
Who is behind it
In the atlas: maintains 6, contributes to 9, wrote 12@mikezaschkamaintainerCora BonnieContributes to this
In the atlas: contributes to 2@corabonnieDavid SooterContributes to this
In the atlas: contributes to 9@d-sooterdeklosdevContributes to this
In the atlas: contributes to 2@deklosdevF7502Contributes to this
In the atlas: contributes to 2@F7502Frank MeertensContributes to this
In the atlas: contributes to 1@frankmeertensGregor WolfContributes to this
In the atlas: maintains 17, contributes to 59, wrote 2@gregorwolfIwona HahnContributes to this
In the atlas: contributes to 7@iwonahahnLothar BenderContributes to this
In the atlas: contributes to 9@LotharBenderrajbhuva1Contributes to this
In the atlas: contributes to 3@rajbhuva1EgorTContributes to this
In the atlas: contributes to 2@Regloom10 contributors
Before choosing this
Signals
RepositoryArchivedThe declared repository is archived
GitHub reports the repository as archived. The package may remain installable, but its source is no longer open for normal maintenance.
Conditions
PracticalFunctional boundary
The repository is archived, so nothing here will move again. Fine to keep where it already runs; anything new should start from what the current cds deploy leaves open rather than from this.
What it declares
Every artifact
- Type
- Build tool
- Origin
- Independently maintained
- Runtime
- Node.js
As a build tool
- Distributed through
- npm
Connections
Fork of cds-dbm with deploy, load, diff and drop tasks
Getting a model change into a database that already holds data
Managed PostgreSQL from the hyperscaler via a BTP service binding
Download
Install
npm add cds-dbmDerived from the package name. No recipe recorded; the README has the configuration.
Learn more
- Run and Deploy SAP CAP (Java) with PostgreSQL using Official Database Adapter @cap-js/postgresRun and Deploy SAP CAP (Java) with PostgreSQL using Official Database Adapter @cap-js/postgresThe post that records a handover. The author's earlier writing relied on the community projects cds-pg and cds-dbm; this one states that both were deprecated in favour of the official PostgreSQL support arriving with @sap/cds 7, and rewrites the path around @cap-js/postgres. For CAP Java it takes a different route to the initial schema.sql than the Node.js case, and it is candid that automatic schema deployment is convenient but not always what you want. Dated evidence for why two artifacts here went quiet.shanthakumar_krishnaswamy, published 2023-08-02shanthakumar_krishnaswamy, SAP Community
- Run and Deploy CAP with PostgreSQL on SAP BTP Cloud Foundry (Node.js)Run and Deploy CAP with PostgreSQL on SAP BTP Cloud Foundry (Node.js)The deployment half of the pair, two weeks after the local one, and superseded the same way: it carries the same banner directing readers to @cap-js/postgres and the official documentation. The two together are the community PostgreSQL path as it stood before the core absorbed it.published 2020-11-30Mike Zaschka, SAP Community
- Getting started with CAP on PostgreSQL (Node.js)Getting started with CAP on PostgreSQL (Node.js)Running CAP on PostgreSQL locally in 2020, when doing so meant the community packages cds-pg and cds-dbm. It now opens with a banner the author added later: @sap/cds 7.0.0 has native PostgreSQL support, use @cap-js/postgres instead, with a pointer to a step-by-step guide for it. Worth having for that banner as much as for the content — a post that tells you not to follow it is a dated fact about where the answer moved.published 2020-11-16Mike Zaschka, SAP Community
README
quoted from mikezaschka/cds-dbm under MIT, readcds-dbm is deprecated and will no longer be actively maintained. Starting with version 7.0.0 @sap/cds now has native support for PostgreSQL. Please use the official database adapter @cap-js/postgres and check out the official documentation for more details.
cds-dbm (Core Data Services – Database Migrations)
cds-dbm is a package that extends the database tooling capabilities of the SAP Cloud Application Programming Model's Node.js Service SDK (@sap/cds) for relational databases other than the native supported ones (SAP HANA and SQLite).
The library offers a set of command line tasks related to deploying a cds data model to the database:
It also contains a sap/@cds builder task to create ready-to-deploy build fragments for SAP Business Technology Platform (BTP) Cloud Foundry:
Current status
cds-dbm is ready to be used!
The library contains all the necessary commands and functionality to build a cds model for and deploy it to the supported databases.
Database support
Internally cds-dbm is relying on the popular Java framework liquibase to handle (most) of the database activities. Liquibase by default has support for a variety of relational databases, but currently cds-dbm offers support for the following ones:
- PostgreSQL (in combination with the
cds-pgdatabase adapter)
Support for other databases is planned whenever a corresponding CDS adapter library is available.
There are some example apps already using cds-dbm in combination with cds-pg:
There are also some blogposts in the SAP Community showcasing the functionality of cds-dbm:
- https://blogs.sap.com/2020/11/16/getting-started-with-cap-on-postgresql-node.js/
- https://blogs.sap.com/2020/11/30/run-and-deploy-cap-with-postgresql-on-sap-cloud-platform-cloud-foundry-node.js/
Why does cds-dbm (currently) not support SAP HANA?
As SAP HANA is a first class citizen in CAP, SAP offers its own deployment solution (@sap/hdi-deploy). With CAP it is possible to directly compile a data model into SAP HANA fragments (.hdbtable, etc.), which can then be deployed by the hdi-deploy module taking care of all the important stuff (delta handling, hdi-management on XSA or SAP BTP, etc.).
Nevertheless it may be suitable to use the liquibase-hanadb adapter to add an alternative deployment solution. If so, support might be added in the future.
How to use
Prerequisites
Since the project uses liquibase internally, a Java Runtime Environment (JRE) in at least version 8 is required on your system.
Usage in your CAP project
Simply add this package to your CAP project by running:
npm install cds-dbm
cds-dbm requires some additional configuration added to your package.json:
"cds": {
//...
"migrations": {
"db": {
"schema": {
"default": "public",
"clone": "_cdsdbm_clone",
"reference": "_cdsdbm_ref"
},
"deploy": {
"tmpFile": "tmp/_autodeploy.json",
"undeployFile": "db/undeploy.json"
}
}
}
}
Internally cds-dbm uses 3 different schemas during deployment:
- default – The schema containing your currently deployed and thus running schema
- clone – A schema that will be a clone of the default schema during deployment
- reference – The schema that will contain the CDS model
Automated delta deployments
TODO: Add full description
In the meantime some notes on the delta processing:
- Clone current db schema
cds.migrations.db.schema.defaultintocds.migrations.db.schema.clone. - Drop all CDS based views from clone schema because updates on views do not work in the way liquibase is handling this via
CREATE OR REPLACE VIEW(https://liquibase.jira.com/browse/CORE-2377). - Deploy the full CDS model to the reference schema
cds.migrations.db.schema.reference. - Let liquibase create a diff between the clone and reference schema (including the recreation of the dropped views).
- Do some adjustments on the changelog (handle undeployment stuff, fix order of things).
- Finally deploy changelog to current schema.
- Load data from .csv files (if requested).
Dropping tables/views
cds-dbm follows a safe approach and does not drop any database tables during deployment. Thus, old tables will still be around even if they are not part of your data model anymore.
You can either remove them manually or rely on cds-dbm to handle this for you.
Undeployment file
An undeployment file makes it possible to specifically list views and tables that should be dropped from the database schema during the deployment.
The undeployment file's path needs to be specified in the package.json configuration (cds.migrations.deploy.undeployFile):
# An example undeploy.json:
{
"views": [],
"tables": [
"csw_beers",
"csw_anotherTable"
]
}
auto-undeployment option
While an undeploy.json file gives you fine grained control, it is also possible to automatically remove tables/views from the database schema. When using the auto-undeploy flag during deployment, cds-dbm will take the cds model as the reference and remove all other existing tables/views.
Commands
The following commands exists for working with cds-dbm in the automated delta deployment mode:
Currently tall tasks must be called with npx
npx cds-dbm <task>
deploy
Performs a delta deployment of the current cds data model to the database. By default no csv files are loaded. If this is required, the load strategy has to be defined (load-via).
Usage
cds-dbm deploy
Flags
create-db(boolean) - If set, the deploy task tries to create the database before actually deploying the data model. The deployment will not break, if the database has already been created before.auto-undeploy(boolean) - WARNING: Drops all tables not known to your data model from the database. This should only be used if your cds includes all tables/views in your db (schema). Otherwise it is highly recommended to use an undeployment file.load-via(string) - Can be eitherfull(truncate and insert) ordelta(check for existing records, then update or insert)dry(boolean) - Does not apply the SQL to the database but logs it to stdout
Examples
cds-dbm deploy
cds-dbm deploy --create-db
cds-dbm deploy --load-via delta
cds-dbm deploy --auto-undeploy
cds-dbm deploy --auto-undeploy --dry
load
Loads data from CSV files into the database. The following conventions apply (according to the default @sap/cds conventions at https://cap.cloud.sap/docs/guides/databases):
- The files must be located in folders db/csv, db/data/, or db/src/csv.
- They contain data for one entity each. File names must follow the pattern -.csv, for example, my.bookshop-Books.csv.
- They must start with a header line that lists the needed element names.
Different to the default mechanism in @sap/cds (which supports only full loads), cds_dbm offers two loading strategies:
full– Truncates a table and then inserts all the data from the CSV filedelta– Checks, if an existing record with the same key exists and performs an update. All other records in the table will be left untouched.
Usage
cds-dbm load --via full
cds-dbm load --via delta
Flags
via(string) - Can be eitherfull(truncate and insert) ordelta(check for existing records, then update or insert)
drop
Drops all tables and views in your data model from the database. If the all parameter is given, then everything in the whole schema will be dropped, not only the cds specific entities.
Usage
cds-dbm drop
Flags
all(boolean) - If set, the whole content of the database/schema is being dropped.
Examples
cds-dbm drop
cds-dbm drop --all
diff
Generates a descriptive text containing all the differences between the defined cds model and the current status of the database. By default, the information will be logged to the console.
Usage
cds-dbm diff
Flags
to-file(string) - If set, the diff information will be written into the file and not logged in the console.
Examples
cds-dbm diff
cds-dbm diff --to-file db/diff.txt
Custom Build Task
Executes the defined cds build task, either from a .cdsrc or the package json. cds-dbm comes with a pre-baked build task, to deploy the data model to a PostgreSQL database on SAP BTP Cloud Foundry.
Example configuration:
"build": {
"tasks": [
{
"use": "node-cf",
"src": "srv"
},
{
"use": "cds-dbm/dist/build/postgres-cf",
"for": "postgres-cf",
"src": "db",
"options": {
"deployCmd": "npx cds-dbm deploy --load-via delta --auto-undeploy"
}
}
]
},
Usage via cds build
cds build
This will generate a specifc set of files into the gen/db (or any other configured) folder, that will be deployed to SAP BTP CF environment.
An example configuration for a mta.yml leveraging the build fragments:
- name: devtoberfest-db-deployer
type: custom
path: gen/db
parameters:
buildpacks: [https://github.com/cloudfoundry/apt-buildpack#v0.2.2, nodejs_buildpack]
no-route: true
no-start: true
disk-quota: 2GB
memory: 512MB
tasks:
- name: deploy_to_postgresql
command: ./deploy.sh
disk-quota: 2GB
memory: 512MB
build-parameters:
ignore: ["node_modules/"]
requires:
- name: devtoberfest-database
resources:
- name: devtoberfest-database
parameters:
path: ./pg-options.json
service: postgresql-db
service-plan: trial
skip-service-updates:
parameters: true
service-tags:
- plain
type: org.cloudfoundry.managed-service
Sponsors
Thank you to p36 (https://p36.io/) for sponsoring this project.
History
Others providing
Compare all 6 on the Schema evolution page →- @quadrio/cds-dbm@quadrio/cds-dbmA published fork of cds-dbm — deploy, load, diff and drop as CDS command-line tasks for relational databases the core does not natively support.independent, capFork of cds-dbm with deploy, load, diff and drop tasks
- @cap-js-community/common@cap-js-community/commonSix independent features for CAP services in one package: replication cache, migration check, rate limiting, a Redis client broker, a local HTML5 repository and a CDM builder.community org, capSix CAP features in one package, from replication cache to rate limitsfrom CAP
- @quadrio/cds-dbm@quadrio/cds-dbmA published fork of cds-dbm — deploy, load, diff and drop as CDS command-line tasks for relational databases the core does not natively support.independent, capFork of cds-dbm with deploy, load, diff and drop tasksfrom CAP
- @sap/cds-mtxs@sap/cds-mtxsMultitenancy, tenant provisioning and model extensibility for CAP.sap official, capMultitenancy, tenant provisioning and extensibility for CAPfrom CAP
- @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, capCAP Node.js runtimefrom CAP
- @sap/hdi-deploy@sap/hdi-deployThe Node.js deployer for SAP HANA Deployment Infrastructure: it writes a database module's design-time files into an HDI container as a delta, and it is what cds deploy runs for SAP HANA.sap official, capNode.js deployer for SAP HANA Deployment Infrastructure containersfrom CAP
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
Contributors
History in the atlas
- Withheld verdicts retired with the rings. Nothing is recused from: facts about an entry are facts whoever maintains it, and a starting-point is answered by description.to_build_on_it.
- First seen.
For your agent
- Ref
artifact:mikezaschka-cds-dbm- JSON
- /artifacts/mikezaschka-cds-dbm.json
- MCP
- Connecting an agent