UNPKG

@sap/cds-dk

Version:

Command line client and development toolkit for the SAP Cloud Application Programming Model

52 lines (44 loc) 1.57 kB
const cds = require('../../../cds') const { read } = cds.utils const { readProject } = require('../../projectReader') const { merge } = require('../../merge') const mvn = require('../../mvn') const { srv4, postgres, postgresDeployer } = require('../../registries/mta') module.exports = class PostgresTemplate extends require('../../plugin') { static help() { return 'database support for PostgreSQL' } async canRun() { const { hasMta, hasHelm, hasHelmUnifiedRuntime } = readProject() if ((hasHelm || hasHelmUnifiedRuntime) && !hasMta) throw `'cds add postgres' is not available for Kyma yet` return true } static hasInProduction(env) { return env.requires?.db?.kind === 'postgres' } async run() { const project = readProject() const { configFile, isJava } = project project.shortcut = typeof (await read(configFile)).cds?.requires?.db !== 'object' await merge(__dirname, 'files/package.json.hbs').into('package.json', { project }) if (isJava) await mvn.add('postgresql') } async combine() { const project = readProject() const { hasMta, srvPath } = project if (hasMta) { const srv = srv4(srvPath) await merge(__dirname, 'files/mta.yml.hbs').into('mta.yaml', { project, additions: [srv, postgres, postgresDeployer], relationships: [{ insert: [postgres, 'name'], into: [srv, 'requires', 'name'] }, { insert: [postgres, 'name'], into: [postgresDeployer, 'requires', 'name'] }] }) } } }