Build toolBuild tooltypeRuns at build time. Nothing of it ships in the deployed application.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

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 PostgreSQL as a delta, for relational databases other than the SAP HANA and SQLite that @sap/cds 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-pg 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, and the repository was archived in July 2023.

Facts

Latestv0.1.4ReleasedLast pushLicenceMIT

Where it sits

Lives in
Provides
Schema evolutionCAPSchema evolutioncapabilityGetting a model change into a database that already holds data, in every tenant, without losing any of it. Generating the initial schema and migrating one that already holds data are often treated as the same step.
Flavors
Node.jsfrom its runtime
Requires
PostgreSQL on SAP BTP, hyperscaler optionPostgreSQL on SAP BTP, hyperscaler optionartifactNamed as a dependency in its documentation.

Who is behind it

Mike ZaschkaMike ZaschkaPersonMaintains this
In the atlas: maintains 6, contributes to 9, wrote 12
@mikezaschka
maintainerCora BonniePersonContributes to this
In the atlas: contributes to 2
@corabonnie
David SooterPersonContributes to this
In the atlas: contributes to 9
@d-sooter
deklosdevPersonContributes to this
In the atlas: contributes to 2
@deklosdev
F7502PersonContributes to this
In the atlas: contributes to 2
@F7502
Frank MeertensPersonContributes to this
In the atlas: contributes to 1
@frankmeertens
Gregor WolfPersonContributes to this
In the atlas: maintains 17, contributes to 59, wrote 2
@gregorwolf
Iwona HahnPersonContributes to this
In the atlas: contributes to 7
@iwonahahn
Lothar BenderPersonContributes to this
In the atlas: contributes to 9
@LotharBender
rajbhuva1PersonContributes to this
In the atlas: contributes to 3
@rajbhuva1
EgorTPersonContributes to this
In the atlas: contributes to 2
@Regloom
10 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

Connections3

Install

npm add cds-dbm

Derived from the package name. No recipe recorded; the README has the configuration.

Learn more3

Readings
  1. Run and Deploy SAP CAP (Java) with PostgreSQL using Official Database Adapter @cap-js/postgresshanthakumar_krishnaswamy, SAP Community
  2. Run and Deploy CAP with PostgreSQL on SAP BTP Cloud Foundry (Node.js)Mike Zaschka, SAP Community
  3. Getting started with CAP on PostgreSQL (Node.js)Mike Zaschka, SAP Community

README

quoted from mikezaschka/cds-dbm under MIT, read
mikezaschka/cds-dbm/readme.mdOn GitHub
cds-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-pg database 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:

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:

  1. Clone current db schema cds.migrations.db.schema.default into cds.migrations.db.schema.clone.
  2. 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).
  3. Deploy the full CDS model to the reference schema cds.migrations.db.schema.reference.
  4. Let liquibase create a diff between the clone and reference schema (including the recreation of the dropped views).
  5. Do some adjustments on the changelog (handle undeployment stuff, fix order of things).
  6. Finally deploy changelog to current schema.
  7. 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 either full (truncate and insert) or delta (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 file
  • delta – 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 either full (truncate and insert) or delta (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.

MIT, read

History

Latest

v0.1.4

Fixes 1

Notes
Bug Fixes
  • add dialect to cds-pg template package (dfee328)
  1. v0.1.3

    Fixes 1

    Notes
    Bug Fixes
  2. v0.1.2

    Fixes 5

    Notes
    Bug Fixes
    • cannot read properties of undefined (c57996b)
    • failed to load model undefined issue (ceff9e7)
    • final correction (ccca821)
    • run for node 18 (e1ce564)
    • use cds.env.build['outputfile'] (6e26f63)
  3. v0.1.1

  4. v0.1.0

    Fixes 5

    Notes
    Bug Fixes
    • cds no longer provided as super property (7d49be0)
    • getHanaDbModuleDescriptor path on @sap/cds (a0f2834)
    • increased jest timeout (4fb6287)
    • Update CDS version and fix tsconfig compile (ab62510)
    • update cds-pg to public version (239ca69)
  5. v0.0.36

  6. v0.0.35

    Fixes 1

    Notes
    Bug Fixes
    • delta update column matching fully lowercase (4e6be32)
  7. v0.0.34

  8. v0.0.33

    Fixes 1

    Notes
    Bug Fixes
    • delta update condition now respects single records (cf180fb)
  9. v0.0.32

    Fixes 1

    Notes
    Bug Fixes
    • handle column names in csv file more save (ae2dbd4)
  10. v0.0.31

  11. v0.0.30

  12. v0.0.29

    Fixes 1

    Notes
    Bug Fixes
    • upgrade jar files to fix vulnerability (7a57d2a)
  13. v0.0.28

    Features 2, Fixes 1

    Notes
    Features
    • remove obsolete build command (f0a9c92)
    • updated @sap/cds to latest (a3b7f23)
    Bug Fixes
    • remove obsolete cds imports (a760497)
  14. v0.0.27

    Fixes 1

    Notes
    Bug Fixes
    • handle more complex cascading views correctly (7bee324)
  15. v0.0.26

    Fixes 1

    Notes
    Bug Fixes
    • only copy schema if specified in package.json (bc8cea0)
  16. v0.0.25

    Features 1, Fixes 1

    Notes
    Features
    • support for latest @sap/cds (ac6f6ad)
    Bug Fixes
    • adjust data loading to changed internal api (63db822)
  17. v0.0.24

  18. v0.0.23

  19. v0.0.22

  20. v0.0.21

  21. v0.0.20

    Features 1, Fixes 1

    Notes
    Features
    • remove not supported SQLite adapter (e0eb17d)
    Bug Fixes
    • handle dropping and creating cascading views (41cd76a)
  22. v0.0.19

  23. v0.0.18

    Features 2, Fixes 1

    Notes
    Features
    • build: add startCmd option (ba3866c)
    • diff: let diff output the diff to the console (163ee14)
    Bug Fixes
    • deploy: make ordering the changelog more robust (6694ffb), closes #6
  24. v0.0.17

    Features 1, Fixes 1

    Notes
    Features
    • build: add support for deployCmd option and copy over undeploy.json (5d0f2d3)
    Bug Fixes
    • liquibase: capture stdout in case of an error (4e46ec7)
  25. v0.0.16

    Fixes 3

    Notes
    Bug Fixes
    • build: use at least version 0.0.16 for cf deployments (b2cedbe)
    • deploy: correct java path (0503d80)
    • deploy: make deploy.sh executable (d6c7b52)
  26. v0.0.15

    Features 1, Fixes 1

    Notes
    Features
    • build: add build task for cf deployments (8b1b9f8)
    Bug Fixes
    • postgresadapter: enable before hook in deploy (99c17df)
  27. v0.0.14

    Features 2, Fixes 1

    Notes
    Features
    • deploy: add option to create a database during deployment (b5234ee)
    • deploy: remove PostgreSQL system related views from changelog (e9a29ea)
    Bug Fixes
  28. v0.0.13

    Fixes 1

    Notes
    Bug Fixes
    • PostgresAdapter: do not rely on global options which may be overwritten (c99bccb)
  29. v0.0.12

    Features 1

    Notes
    Features
    • check and create database if not available (8dddaf4)
  30. v0.0.11

    Fixes 6

    Notes
    Bug Fixes
  31. v0.0.10

  32. v0.0.9

    Fixes 1

    Notes
    Bug Fixes
    • make dry deploy runs not load data and fix console output (d1e52f0)
  33. v0.0.8

  34. v0.0.7

    Fixes 2

    Notes
    Bug Fixes
    • csv file to db name mapping (e6c1edf)
    • use regex instead of replaceAll (ecb6a7a)
  35. v0.0.6

  36. v0.0.5

    Fixes 1

    Notes
    Bug Fixes
    • add simple log statement to indicate file loading (51b3d18)
  37. v0.0.4

  38. v0.0.3

  39. v0.0.2

    Features 2, Fixes 4

    Notes
    Features
    • big update of latest developments (75c6802)
    • initial commit (38384b5)
    Bug Fixes
    • add tmp path if not available (2f8f998)
    • create changelog directories (324f44e)
    • fix tests by resetting options correctly (71a74bd)
    • fix typescript target to support node10 (0a37199)
133downloads per week, npm
Weekly downloads for cds-dbm26 complete calendar weeks from 2026-04-27 to 2026-10-25; the latest total is 133.27 Apr – 3 May: 1,0324 May – 10 May: 83411 May – 17 May: 1,04318 May – 24 May: 1,86525 May – 31 May: 1,3511 Jun – 7 Jun: 1,0088 Jun – 14 Jun: 1,30915 Jun – 21 Jun: 1,18222 Jun – 28 Jun: 1,34729 Jun – 5 Jul: 1,0876 Jul – 12 Jul: 1,34413 Jul – 19 Jul: 1,28620 Jul – 26 Jul: 1,12127 Jul – 2 Aug: 9913 Aug – 9 Aug: 93010 Aug – 16 Aug: 83117 Aug – 23 Aug: 85424 Aug – 30 Aug: 76531 Aug – 6 Sept: 7127 Sept – 13 Sept: 58114 Sept – 20 Sept: 60121 Sept – 27 Sept: 75128 Sept – 4 Oct: 7355 Oct – 11 Oct: 68012 Oct – 18 Oct: 37819 Oct – 25 Oct: 133
Declared alternative
  1. @quadrio/cds-dbmFork of cds-dbm with deploy, load, diff and drop tasks
Schema evolution
  1. @cap-js-community/commonSix CAP features in one package, from replication cache to rate limitsfrom CAP
  2. @quadrio/cds-dbmFork of cds-dbm with deploy, load, diff and drop tasksfrom CAP
  3. @sap/cds-mtxsMultitenancy, tenant provisioning and extensibility for CAPfrom CAP
  4. @sap/cdsCAP Node.js runtimefrom CAP
  5. @sap/hdi-deployNode.js deployer for SAP HANA Deployment Infrastructure containersfrom CAP

Details

Sources5
npm registrydiscovered herechecked
The maintainer, claiming itdiscovered herechecked
npm registry, cds-dbmversion, releases, installschecked
github.com/git+https://github.com/mikezaschka/cds-dbm.gittree, pushes, contributors, CIchecked
readme.mdquoted, and what the entry declareschecked

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
runtimesnode
latestv0.1.4
first release
releases and cadence39, ~1d median
discovered vianpm registry, The maintainer, claiming it
first seen in the atlas
ecosystem and domaincap, data-and-persistence
Contributors10
History in the atlas2
  1. 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.
  2. First seen.
For your agent
Ref
artifact:mikezaschka-cds-dbm
JSON
/artifacts/mikezaschka-cds-dbm.json
MCP
Connecting an agent