Skip to content

Commit 2956279

Browse files
feat: Persist assert_integrity feature (#1032)
Fixes #1020 --------- Co-authored-by: Patrice Bender <[email protected]>
1 parent 1e0a615 commit 2956279

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

postgres/cds-plugin.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,23 @@ cds.build?.register?.('postgres', class PostgresBuildPlugin extends cds.build.Pl
2525
if (fs.existsSync(path.join(this.task.src, 'package.json'))) {
2626
promises.push(this.copy(path.join(this.task.src, 'package.json')).to('package.json'))
2727
} else {
28-
promises.push(
29-
this.write({
30-
dependencies: { '@sap/cds': '^8', '@cap-js/postgres': '^1' },
31-
scripts: { start: 'cds-deploy' },
32-
}).to('package.json'),
28+
const packageJson = {
29+
dependencies: {
30+
'@sap/cds': '^8',
31+
'@cap-js/postgres': '^1'
32+
},
33+
scripts: {
34+
start: 'cds-deploy'
35+
}
36+
}
37+
const assertIntegrity = cds.env?.features?.assert_integrity
38+
if (assertIntegrity) {
39+
packageJson.cds ??= {}
40+
packageJson.cds.features ??= {}
41+
packageJson.cds.features.assert_integrity = assertIntegrity
42+
}
43+
promises.push(
44+
this.write(packageJson).to('package.json')
3345
)
3446
}
3547
promises.push(this.write(cds.compile.to.json(model)).to(path.join('db', 'csn.json')))

postgres/test/cds-build.test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const cds = require('../../test/cds.js')
99

1010
const workDir = path.join(__dirname, 'tiny-sample')
1111
const genDir = path.join(workDir, 'gen')
12-
const dbDest = path.join(genDir, 'pg/db')
12+
const pgDest = path.join(genDir, 'pg')
13+
const dbDest = path.join(pgDest, 'db')
1314

1415
// delete the generated folder after each test
1516
afterEach(() => {
@@ -27,4 +28,12 @@ describe('cds build plugin', () => {
2728
execSync('npx cds build --production', { cwd: workDir })
2829
expect(fs.existsSync(path.join(dbDest, 'csn.json'))).to.be.true
2930
})
31+
32+
test('should retain assert_integrity setting', () => {
33+
execSync('npx cds build --production', { cwd: workDir })
34+
const packageJson = require(path.join(pgDest, 'package.json'))
35+
expect(packageJson.cds?.features?.assert_integrity).to.equal('db')
36+
const ddl = String(execSync('npx cds deploy --dry', { cwd: workDir }))
37+
expect(ddl).to.contain('REFERENCES')
38+
})
3039
})

postgres/test/tiny-sample/db/schema.cds

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ entity Books {
44
key ID : Integer;
55
title : String;
66
stock : Integer;
7+
author : Association to Authors;
8+
}
9+
10+
entity Authors {
11+
key ID : Integer;
712
}

postgres/test/tiny-sample/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
"description": "A simple CAP project, to test the build plugin",
55
"dependencies": {
66
"@cap-js/postgres": "../../."
7+
},
8+
"cds": {
9+
"features": {
10+
"assert_integrity": "db"
11+
}
712
}
813
}

0 commit comments

Comments
 (0)