@cds-pgroll/postgres
The destructive half of 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. schema evolution — DROP and RENAME, which CAP's own schema_evolution: alter will not perform — driven from the command line beside @cap-js/postgres.
Facts
Where it sits
Who is behind it
In the atlas: maintains 1, contributes to 1@Medelkouch98maintainer
Before choosing this
Conditions
LicenceSAP Developer License Agreement 3.2 CAP§ 1from Database connectorsA covered CAP application uses a connector to copy or persist SAP product data in a non-SAP database product.
- § 1 License. Productive customer applications are limited to SAP BTP or another SAP-licensed platform, and mass extraction to a non-SAP product is restricted except where solely required for SAP interoperability.
The connector itself does not decide the licence boundary. Section 1 makes the destination and purpose of extraction relevant, including the scoped exception for interoperability with an SAP product.
SAP Developer License Agreement 3.2 CAP →What it declares
Every artifact
- Type
- CLI
- Origin
- Independently maintained
As a CLI
- Declared for
- >=7
- Distributed through
- npm
Connections
Connecting a data model and its queries to a database
Managed PostgreSQL from the hyperscaler via a BTP service binding
A 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.
Download
Install
npm add @cds-pgroll/postgresDerived from the package name. No recipe recorded; the README has the configuration.
Architecture
Download
README
quoted from Medelkouch98/cds-pgroll under MIT, read@cds-pgroll/postgres
Complementary migration toolkit for @cap-js/postgres. Handles destructive DDL operations (DROP, RENAME) that CAP's schema_evolution: 'alter' cannot perform.
Why?
SAP CAP with @cap-js/postgres supports schema_evolution: 'alter' which can:
- ✅ ADD tables, ADD columns, ALTER column types
But it cannot:
- ❌ DROP tables, DROP columns
- ❌ RENAME tables, RENAME columns
- ❌ DROP NOT NULL, SET DEFAULT
@cds-pgroll/postgres fills this gap with pgroll-inspired migrations that run before CAP's cds-deploy, handling the destructive/rename DDL that CAP leaves behind.
Architecture
┌─────────────────────────────────────────────────────┐
│ CF Deployment │
│ │
│ 1. pgroll-migrator (CF task) │
│ ├── Phase 1: Auto-detect CSN delta │
│ │ Compare old cds_model with new csn.json │
│ │ → Generate DROP operations automatically │
│ └── Phase 2: Apply manual migration files │
│ → Run *.json from migrations/ directory │
│ │
│ 2. db-deployer (deployed-after pgroll-migrator) │
│ └── cds-deploy --model-only │
│ → ADD tables, ALTER columns, update cds_model│
│ │
│ 3. srv (deployed-after db-deployer) │
│ └── Application server │
└─────────────────────────────────────────────────────┘
Installation
npm install @cds-pgroll/postgres --save-dev
Quick Start
1. Initialize
npx cds-pgroll init
Creates a schema snapshot in migrations/.schema-snapshot.json.
2. Make schema changes
Edit db/schema.cds — remove a column, drop an entity, etc.
3. Generate migration
npx cds-pgroll generate
Interactive CLI that creates a migration JSON file in migrations/.
4. Apply locally
npx cds-pgroll apply
5. Check status
npx cds-pgroll status
Configuration
Add to your package.json:
{
"cds-pgroll": {
"schema": "cap_tva",
"migrationsDir": "migrations",
"schemaPath": "db/schema.cds",
"dataDir": "db/data",
"schemaEvolution": "alter"
}
}
Or use environment variables:
CAP_DB_SCHEMA— PostgreSQL schema nameCAP_SCHEMA_EVOLUTION— Schema evolution mode
Migration File Format
Migration files are JSON with a name and operations array:
{
"name": "20260311_120000_drop_payment_category",
"operations": [
{
"drop_column": {
"table": "CAP_TVA_DB_FINANCIALDOCUMENTS",
"column": "paymentcategory",
"down": "SELECT NULL"
}
}
]
}
Supported Operations
| Operation | Description | Example |
|---|---|---|
drop_column | Remove a column | { "table": "T", "column": "C", "down": "SELECT NULL" } |
drop_table | Remove a table | { "table": "T" } |
rename_column | Rename a column | { "table": "T", "from": "old", "to": "new" } |
rename_table | Rename a table | { "from": "OLD_T", "to": "NEW_T" } |
alter_column | Change column type | { "table": "T", "column": "C", "type": "VARCHAR(500)", "up": "CAST...", "down": "CAST..." } |
add_column | Add a column | { "table": "T", "column": { "name": "C", "type": "VARCHAR(100)" } } |
set_not_null | Add NOT NULL | { "table": "T", "column": "C" } |
drop_not_null | Remove NOT NULL | { "table": "T", "column": "C" } |
set_default | Set default value | { "table": "T", "column": "C", "default": "'value'" } |
drop_default | Remove default | { "table": "T", "column": "C" } |
create_table | Create a table | { "table": "T", "columns": [...], "data": [...] } |
raw_sql | Raw SQL statement | { "up": "CREATE INDEX ...", "down": "DROP INDEX ..." } |
MTA Integration
For Cloud Foundry deployments, add a pgroll-migrator module to your mta.yaml. See examples/mta-module.yaml for a complete example.
Key points:
- Add
npx cds-pgroll preparetobefore-allbuild commands - Copy migration files to
gen/migrations/during build - Set
deployed-afteron db-deployer to ensure correct ordering - Use
--model-onlyflag forcds-deployso CAP doesn't attempt DDL
Build Commands
build-parameters:
before-all:
- builder: custom
commands:
- npm ci
- npx cds build --production
- npx cds-pgroll prepare
- 'sed -i ''s/"start": "cds-deploy"/"start": "cds-deploy --model-only"/'' gen/pg/package.json'
- mkdir -p gen/migrations
- cp migrations/package.json gen/migrations/
- cp migrations/run-pgroll.js gen/migrations/
- bash -c "cp migrations/*.json gen/migrations/ 2>/dev/null; exit 0"
- cp gen/pg/db/csn.json gen/migrations/csn.json
API Reference
Core Functions
const {
// Type mapping
cdsTypeToSql, // Convert CDS type to PostgreSQL type
// Naming
entityToTableName, // CDS entity → PG table name
quoteIdent, // Safe SQL identifier quoting
// Operations
applyOperation, // Execute a pgroll operation against PG
tableExists, // Check if table exists
columnExists, // Check if column exists
// CSN comparison
detectSchemaChanges, // Compare CSNs for destructive changes
parseStoredCSN, // Parse CSN from cds_model TEXT column
// SQL helpers
PgRollSql, // Migration tracking (init, record, query)
// High-level
runMigrations, // Full 2-phase pipeline
generate, // Interactive migration generator
prepareDeployer, // Prepare gen/pg for deployment
} = require('@cds-pgroll/postgres');
PgRollSql Class
const { PgRollSql } = require('@cds-pgroll/postgres');
const { Client } = require('pg');
const client = new Client({ /* connection config */ });
await client.connect();
const sql = new PgRollSql(client, 'cap_tva');
await sql.initializeSchema();
// Query migrations
const migrations = await sql.getMigrations();
const pending = await sql.getPendingMigrations(['file1', 'file2']);
const health = await sql.healthCheck();
// Record a migration
await sql.recordMigration('my_migration', [{ drop_table: { table: 'T' } }]);
CDS Type Mapping
| CDS Type | PostgreSQL Type |
|---|---|
cds.UUID | VARCHAR(36) |
cds.String | VARCHAR(length) or VARCHAR(5000) |
cds.LargeString | TEXT |
cds.Integer | INTEGER |
cds.Integer64 | BIGINT |
cds.Decimal | DECIMAL(p,s) or DECIMAL |
cds.Double | FLOAT8 |
cds.Boolean | BOOLEAN |
cds.Date | DATE |
cds.Time | TIME |
cds.DateTime | TIMESTAMP |
cds.Timestamp | TIMESTAMP |
cds.Binary | BYTEA |
cds.LargeBinary | BYTEA |
How It Differs from pgroll
This is not the pgroll binary. It is a lightweight, CDS-aware migration runner that borrows pgroll's JSON operation format. Key differences:
- No expand/contract pattern (CAP handles schema evolution)
- No shadow columns or views
- Direct DDL execution with proper identifier quoting
- Integrated CSN delta detection
- CDS type system awareness
License
MIT
History
Others providing
Compare all 22 on the Database connectors page →- SAP HANA CloudSAP HANA CloudThe managed database under most of this: CAP's default target, the store Datasphere and Analytics Cloud sit on, and a service with plans and components.sap official, btpManaged SAP HANA database service on BTP
- PostgreSQL on SAP BTP, hyperscaler optionPostgreSQL on SAP BTP, hyperscaler optionA managed PostgreSQL from the underlying hyperscaler — AWS, Azure, Google Cloud or Alicloud — consumed through a BTP service binding.sap official, btpManaged PostgreSQL from the hyperscaler via a BTP service binding
- com.sap.cds:cds-feature-hanacom.sap.cds:cds-feature-hanaThe CAP Java feature that wires a Maven application to SAP HANA Cloud, the production default among CAP's supported databases.sap official, capSAP HANA Cloud datasource for CAP Java applications
- com.sap.cds:cds-feature-jdbccom.sap.cds:cds-feature-jdbcConnects the CAP Java runtime to JDBC databases through the CDS4j JDBC runtime: H2 and SQLite, which capire names for local development and CI tests rather than enterprise use.sap official, capJDBC runtime for H2 and SQLite in CAP Java
- com.sap.cds:cds-feature-postgresqlcom.sap.cds:cds-feature-postgresqlThe CAP Java feature that wires a Maven application to PostgreSQL as its datasource beside SAP HANA, with limitations capire lists: schema evolution first, and no multitenancy or extensibility yet.sap official, capPostgreSQL datasource for CAP Java applications
- com.sap.cds:cds-services-bomcom.sap.cds:cds-services-bomThe Maven bill of materials for CAP Java, pinning every com.sap.cds module in a release, from the API and core runtime to the Spring Boot starters and the CQN engine, to the same version.sap official, capMaven bill of materials pinning CAP Java module versions
- @cap-js/db-service@cap-js/db-serviceThe base every CAP database service is built on: the shared query translation and pooling that SQLite, PostgreSQL and HANA specialise rather than reimplement.sap official, capBase service shared by CAP's SQLite, PostgreSQL and HANA services
- @cap-js/hana@cap-js/hanaThe HANA database service — the production default, on the same streamlined architecture as the SQLite and PostgreSQL services.sap official, capSAP HANA database service for CAP
- @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, capPostgreSQL database service for CAP
- @cap-js/sqlite@cap-js/sqliteThe SQLite service, in memory during the inner loop — which is why a CAP project runs before anyone has provisioned a database.sap official, capSQLite database service for CAP, in memory during development
- cap-postgres-btp-connectivitycap-postgres-btp-connectivityConnects a CAP Node.js application to a PostgreSQL database that is not publicly reachable, tunnelling through BTP Connectivity and the Cloud Connector.independent, capTunnels CAP Node.js to a private PostgreSQL via Cloud Connector
- cds-mongodbcds-mongodbMongoDB as a native CAP database service, through Mongoose — CQN reads and writes, managed associations as ObjectId references, $expand resolved by populate, and cds deploy --to mongoose.independent, capMongoDB as a CAP database service through Mongoose
- @neoimpulse/cap-js-restore-model-defined-types@neoimpulse/cap-js-restore-model-defined-typesA CAP plugin that casts values back to the types the CDS model declares after a READ, for the entities you name, where the database driver returned them as strings.independent, capCAP plugin casting read values back to CDS model types
- @quadrio/cds-db2@quadrio/cds-db2A DB2 adapter for CDS, so a CAP model can be deployed to and served from DB2, last released July 2023 and still on npm while the repository it was published from has been deleted.independent, capDB2 adapter for CDS
- @sap/cds-hana@sap/cds-hanaThe SAP Cloud Application Programming Model's database adapter for SAP HANA, the package a CAP project adds to run its model on a SAP HANA database.sap official, capDatabase adapter for SAP HANA in 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 runtime
- @sap/hana-client@sap/hana-clientSAP's own Node.js driver for SAP HANA: connect, run SQL and prepared statements, synchronously, through callbacks or as promises, over native client libraries npm installs per platform.sap official, btpSAP's Node.js driver for SAP HANA
- SAP HANASAP HANASAP’s relational database platform, which stores application data and executes SQL and SQLScript in the database, available on-premise and as the managed service SAP HANA Cloud.sap official, btpSAP's relational database platform, on-premise and in HANA Cloud
- 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, capPostgreSQL adapter for SAP CDS from the SAP Mentors community
- cap-snowflakecap-snowflakeA CAP database adapter for Snowflake with OData V4 support, which the maintainer marks as early development, so its contract is expected to move.independent, capCAP database adapter for Snowflake with OData V4 support
- cds-mysqlcds-mysqlA MySQL and MariaDB database adapter for CAP that connects to a database instance and translates incoming CQL/CQN requests to it; the repository the package declares has been deleted.independent, capMySQL and MariaDB database adapter for 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
Flavors
“npm install @cds-pgroll/postgres --save-dev” — Medelkouch98/cds-pgroll — README
History in the atlas
- Typed cds-plugin by placement, which defaults every candidate to that. It is not one.
- The destructive half of PostgreSQL schema evolution — DROP and RENAME, which CAP's own `schema_evolution: alter` will not perform — driven from the command line beside @cap-js/postgres.
- First seen.
For your agent
- Ref
artifact:cds-pgroll-postgres- JSON
- /artifacts/cds-pgroll-postgres.json
- MCP
- Connecting an agent