Skip to content

cds deploy --to postgres accepts command but doesn't create schema #1471

@aech

Description

@aech

Issue 1: cds deploy --to postgres accepts command but doesn't create schema

Labels

  • bug
  • cli
  • postgresql
  • ux

Description

The command cds deploy --to postgres is accepted by the CLI but only imports CSV data without creating the database schema (tables, views). This leads to confusion as cds deploy --to sqlite works perfectly (creating schema + importing data), but cds deploy --to postgres does not behave identically.

Steps to Reproduce

  1. Create a new CAP project:

    cds init my-project
    cd my-project
    cds add sample
    cds add postgres
    npm install
  2. Start PostgreSQL (e.g., via Docker):

    docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:17
  3. Configure .cdsrc.json:

    {
      "requires": {
        "db": {
          "kind": "postgres",
          "credentials": {
            "host": "localhost",
            "port": 5432,
            "user": "postgres",
            "password": "postgres",
            "database": "bookshop"
          }
        }
      }
    }
  4. Run deploy:

    cds deploy --to postgres

Expected Behavior

One of the following:

  1. Create schema + import data (like cds deploy --to sqlite does)
  2. Throw an error with clear message: "postgres" is not supported for --to, use --profile pg instead

Actual Behavior

  • Command succeeds without error
  • Only CSV data is imported
  • No tables/views are created
  • Database remains empty (except for some imported rows that fail)

Output:

> init from db/data/sap.capire.bookshop-Authors.csv
/> successfully deployed to localhost:5432

But querying the database shows no tables exist.

Root Cause Analysis

cds help deploy lists only "sqlite" and "hana" as supported targets:

SYNOPSIS
    cds deploy [ <model> ] [ --to <database> ]

OPTIONS
    --to <database>  sqlite | hana

PostgreSQL is not listed, yet the command is accepted. The --to flag seems to be ignored, resulting in partial deployment.

Workaround

Use the correct command:

cds deploy --profile pg  # This works correctly

Or for explicit deployment:

cds deploy

Suggested Solution

Option A (preferred): Support --to postgres properly with identical behavior to SQLite

Implement full schema deployment for PostgreSQL to match cds deploy --to sqlite behavior:

  • Create database schema (tables, views, indexes)
  • Import CSV data
  • Set up constraints and relationships

This provides consistent UX across all database types.

Option B: Throw an error when --to postgres is used:

Error: "postgres" is not a valid target for --to flag.
       For PostgreSQL deployment, use: cds deploy --profile pg

       Supported targets: sqlite, hana

Environment

  • @sap/cds: v9.6.3
  • @cap-js/postgres: v2.1.2
  • Node.js: v22.22.0
  • PostgreSQL: 17
  • OS: Ubuntu 24.04 (WSL2)

Related Issues

Additional Context

The confusion stems from the fact that cds deploy --to sqlite works perfectly (creating schema + importing data), leading developers to naturally assume --to postgres would behave identically. This inconsistency creates a poor developer experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions