Skip to content

Commit

Permalink
fix: postgres build plugin w --production (#1018)
Browse files Browse the repository at this point in the history
as reported in the issue, with default `cds build --production` no
postgres build artifacts have been generated.

this was due to a misconfiguration in our `postgres/package.json`

---

```shell
cds init reproduce --add tiny-sample
cd reproduce
cds add postgres
```

you can now observe the malformed `cds env`

```shell
❯ cds env requires.db --profile production
{
  impl: '@cap-js/postgres',
  credentials: { url: 'db.sqlite' },
  kind: 'sqlite',
  dialect: 'postgres',
  vcap: { label: 'postgresql-db' },
  schema_evolution: 'auto'
}
```

and the broken build (missing postgres build task):

```
❯ cds build --production
building project [/Users/patricebender/SAPDevelop/dev/cds-dbs/postgres/test/tiny-sample], clean [true]
cds-dk [8.7.1], cds [8.8.0], compiler [5.7.5], home [/Users/patricebender/SAPDevelop/dev/cds]

{
  build: {
    target: 'gen',
    tasks: [
      { for: 'nodejs', src: 'srv', options: { model: ['db', 'srv'] }}
    ]
  }
}
```
  • Loading branch information
patricebender authored Feb 9, 2025
1 parent 4bc0af2 commit aafffc9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
cache: 'npm'

- run: npm ci
- run: npm install -g @sap/cds-dk
- run: npm run lint
- id: hxe
uses: ./.github/actions/hxe
Expand Down
2 changes: 1 addition & 1 deletion postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"postgres": {
"impl": "@cap-js/postgres",
"kind": "sqlite",
"kind": "postgres",
"dialect": "postgres",
"vcap": {
"label": "postgresql-db"
Expand Down
30 changes: 30 additions & 0 deletions postgres/test/cds-build.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

// make sure the build plugin works

const path = require('path')
const fs = require('fs')
const { execSync } = require('child_process')
const cds = require('../../test/cds.js')

const workDir = path.join(__dirname, 'tiny-sample')
const genDir = path.join(workDir, 'gen')
const dbDest = path.join(genDir, 'pg/db')

// delete the generated folder after each test
afterEach(() => {
if (fs.existsSync(genDir)) fs.rmSync(genDir, { recursive: true })
})

describe('cds build plugin', () => {
const { expect } = cds.test
test('should run pg build with explicit build task', () => {
execSync('npx cds build --for postgres', { cwd: workDir })
expect(fs.existsSync(path.join(dbDest, 'csn.json'))).to.be.true
})

test('should run pg build with production profile', () => {
execSync('npx cds build --production', { cwd: workDir })
expect(fs.existsSync(path.join(dbDest, 'csn.json'))).to.be.true
})
})
3 changes: 3 additions & 0 deletions postgres/test/tiny-sample/db/data/my.bookshop-Books.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ID,title,stock
1,Wuthering Heights,100
2,Jane Eyre,500
7 changes: 7 additions & 0 deletions postgres/test/tiny-sample/db/schema.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace my.bookshop;

entity Books {
key ID : Integer;
title : String;
stock : Integer;
}
8 changes: 8 additions & 0 deletions postgres/test/tiny-sample/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "tiny-sample",
"version": "1.0.0",
"description": "A simple CAP project, to test the build plugin",
"dependencies": {
"@cap-js/postgres": "../../."
}
}
5 changes: 5 additions & 0 deletions postgres/test/tiny-sample/srv/cat-service.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using my.bookshop as my from '../db/schema';

service CatalogService {
@readonly entity Books as projection on my.Books;
}

0 comments on commit aafffc9

Please sign in to comment.