CLICLItypeA command you run, rather than a dependency you import.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-pgroll/postgres

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.

Facts

Latestv1.0.6ReleasedLast pushLicenceMIT

Where it sits

Lives in
Provides
Database connectorsCAPDatabase connectorscapabilityConnecting an application’s data model and queries to a database, including the differences in supported queries, types and schema management between database implementations. Changing an existing schema belongs to [schema evolution](capability:schema-evolution).
Flavors
Requires
@sap/cds≥ 7@sap/cdsartifactThe peer range, as published.PostgreSQLPostgreSQLoutside the atlasNamed as a dependency in its documentation.

Who is behind it

Medelkouch98Medelkouch98PersonMaintains this
In the atlas: maintains 1, contributes to 1
@Medelkouch98
maintainer

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

Connections3

Install

npm add @cds-pgroll/postgres

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

Where @cds-pgroll/postgres runsBy its type: a CLI is run from a terminalcallsdocumentedrequiresYour terminal, actorYour terminalPostgreSQL, systemPostgreSQLsystem@cds-pgroll/postgres, module@cds-pgroll/postgres
SAPnot SAP's, or the project's ownstated in the documentdocumented only

README

quoted from Medelkouch98/cds-pgroll under MIT, read
Medelkouch98/cds-pgroll/README.mdOn GitHub

@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 name
  • CAP_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
OperationDescriptionExample
drop_columnRemove a column{ "table": "T", "column": "C", "down": "SELECT NULL" }
drop_tableRemove a table{ "table": "T" }
rename_columnRename a column{ "table": "T", "from": "old", "to": "new" }
rename_tableRename a table{ "from": "OLD_T", "to": "NEW_T" }
alter_columnChange column type{ "table": "T", "column": "C", "type": "VARCHAR(500)", "up": "CAST...", "down": "CAST..." }
add_columnAdd a column{ "table": "T", "column": { "name": "C", "type": "VARCHAR(100)" } }
set_not_nullAdd NOT NULL{ "table": "T", "column": "C" }
drop_not_nullRemove NOT NULL{ "table": "T", "column": "C" }
set_defaultSet default value{ "table": "T", "column": "C", "default": "'value'" }
drop_defaultRemove default{ "table": "T", "column": "C" }
create_tableCreate a table{ "table": "T", "columns": [...], "data": [...] }
raw_sqlRaw 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:

  1. Add npx cds-pgroll prepare to before-all build commands
  2. Copy migration files to gen/migrations/ during build
  3. Set deployed-after on db-deployer to ensure correct ordering
  4. Use --model-only flag for cds-deploy so 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 TypePostgreSQL Type
cds.UUIDVARCHAR(36)
cds.StringVARCHAR(length) or VARCHAR(5000)
cds.LargeStringTEXT
cds.IntegerINTEGER
cds.Integer64BIGINT
cds.DecimalDECIMAL(p,s) or DECIMAL
cds.DoubleFLOAT8
cds.BooleanBOOLEAN
cds.DateDATE
cds.TimeTIME
cds.DateTimeTIMESTAMP
cds.TimestampTIMESTAMP
cds.BinaryBYTEA
cds.LargeBinaryBYTEA

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

MIT, read

History

Latest

v1.0.1

Fixes 1

Notes
Bug Fixes
  • normalize bin path and repository URL in package.json (0f9dd66)
  1. v1.0.0

    Features 2

    Notes
    Features
    • add semantic-release for automatic versioning (b200706)
    • initial release of @cds-pgroll/postgres (db7cb46)
0downloads per week, npm
Weekly downloads for @cds-pgroll/postgres26 complete calendar weeks from 2026-04-27 to 2026-10-25; the latest total is 0.27 Apr – 3 May: 174 May – 10 May: 2911 May – 17 May: 3118 May – 24 May: 2225 May – 31 May: 311 Jun – 7 Jun: 118 Jun – 14 Jun: 615 Jun – 21 Jun: 2422 Jun – 28 Jun: 2329 Jun – 5 Jul: 376 Jul – 12 Jul: 1313 Jul – 19 Jul: 420 Jul – 26 Jul: 1427 Jul – 2 Aug: 243 Aug – 9 Aug: 1410 Aug – 16 Aug: 917 Aug – 23 Aug: 324 Aug – 30 Aug: 1231 Aug – 6 Sept: 67 Sept – 13 Sept: 1914 Sept – 20 Sept: 4021 Sept – 27 Sept: 828 Sept – 4 Oct: 55 Oct – 11 Oct: 312 Oct – 18 Oct: 119 Oct – 25 Oct: 0
Database connectors
  1. SAP ASE ServiceManaged SAP ASE databases on BTP for Java applicationsfrom BTP/BAIP
  2. SAP HANA CloudManaged SAP HANA database service on BTPfrom BTP/BAIP
  3. SAP HANA Service (SAP Regions) for SAP BTPManaged SAP HANA 2.0 databases in fixed sizes on SAP BTPfrom BTP/BAIP
  4. PostgreSQL on SAP BTP, hyperscaler optionManaged PostgreSQL from the hyperscaler via a BTP service bindingfrom BTP/BAIP
  5. com.sap.cds:cds-feature-hanaSAP HANA Cloud datasource for CAP Java applicationsfrom CAP
  6. com.sap.cds:cds-feature-jdbcJDBC runtime for H2 and SQLite in CAP Javafrom CAP
  7. com.sap.cds:cds-feature-postgresqlPostgreSQL datasource for CAP Java applicationsfrom CAP
  8. com.sap.cds:cds-services-bomMaven bill of materials pinning CAP Java module versionsfrom CAP
  9. @cap-js/db-serviceBase service shared by CAP's SQLite, PostgreSQL and HANA servicesfrom CAP
  10. @cap-js/hanaSAP HANA database service for CAPfrom CAP
  11. @cap-js/postgresPostgreSQL database service for CAPfrom CAP
  12. @cap-js/sqliteSQLite database service for CAP, in memory during developmentfrom CAP
  13. cap-postgres-btp-connectivityTunnels CAP Node.js to a private PostgreSQL via Cloud Connectorfrom CAP
  14. cds-mongodbMongoDB as a CAP database service through Mongoosefrom CAP
  15. hdbPure JavaScript SAP HANA driver for Node.jsfrom BTP/BAIP
  16. @neoimpulse/cap-js-restore-model-defined-typesCAP plugin casting read values back to CDS model typesfrom CAP
  17. @quadrio/cds-db2DB2 adapter for CDSfrom CAP
  18. @sap/cds-hanaDatabase adapter for SAP HANA in CAPfrom CAP
  19. @sap/cdsCAP Node.js runtimefrom CAP
  20. @sap/hana-clientSAP's Node.js driver for SAP HANAfrom BTP/BAIP
  21. SAP HANASAP's relational database platform, on-premise and in HANA Cloudfrom BTP/BAIP
  22. SAP-samples/hana-hdbext-promisfied-examplePromise-based wrappers around the SAP HANA client librariesfrom BTP/BAIP
  23. cds-pgPostgreSQL adapter for SAP CDS from the SAP Mentors communityfrom CAP
  24. cap-snowflakeCAP database adapter for Snowflake with OData V4 supportfrom CAP
  25. cds-mysqlMySQL and MariaDB database adapter for CAPfrom CAP

Details

Sources5
npm registrydiscovered herechecked
The discovery passdiscovered herechecked
npm registry, @cds-pgroll/postgresversion, releases, installschecked
github.com/git+https://github.com/Medelkouch98/cds-pgroll.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
declared for>=7
latestv1.0.6
first release
releases and cadence7, ~0d median
discovered vianpm registry, The discovery pass
first seen in the atlas
ecosystem and domaincap, data-and-persistence
Flavors1
Node.js
“npm install @cds-pgroll/postgres --save-dev” — Medelkouch98/cds-pgroll — READMEchecked
History in the atlas3
  1. Typed cds-plugin by placement, which defaults every candidate to that. It is not one.
  2. 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.
  3. First seen.
For your agent
Ref
artifact:cds-pgroll-postgres
JSON
/artifacts/cds-pgroll-postgres.json
MCP
Connecting an agent