<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Start a js script before deployment in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/start-a-js-script-before-deployment/qaa-p/12777229#M4796993</link>
    <description>&lt;P&gt;DB deployment happens in a task run in cloud foundry run in DB deployer module/application. I suppose your script will run as part of the same task. If so, you need to package your script in the  DB deployer module/application. I suppose it has some influence over what deploy.sh does.  You can then adjust the command of the task to run your script too; just add it the command before `&amp;amp;&amp;amp; ./deploy.sh`&lt;/P&gt;</description>
    <pubDate>Fri, 04 Aug 2023 14:09:02 GMT</pubDate>
    <dc:creator>Dinu</dc:creator>
    <dc:date>2023-08-04T14:09:02Z</dc:date>
    <item>
      <title>Start a js script before deployment</title>
      <link>https://community.sap.com/t5/technology-q-a/start-a-js-script-before-deployment/qaq-p/12777228</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
  &lt;P&gt;I'm having difficulty configuring my project correctly: I would like that when I deploy first of all (or at least, before deploying the db) a script in my project is run.&lt;/P&gt;
  &lt;P&gt;If it helps, the script is in the same location as the mta, and below is the configuration of both my mta and my package.json&lt;/P&gt;
  &lt;P&gt;mta.yaml&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;_schema-version: '3.1'
ID: sfadb
version: 1.0.0
description: "Shared db for sfa applications."
parameters:
  enable-parallel-deployments: true
build-parameters:
  before-all:
    - builder: custom
      commands:
        - npm install --production
        - npx cds build --production

modules:

  #Main Module
  - name: sfadb-srv
    type: nodejs
    path: gen/srv
    parameters:
      buildpack: nodejs_buildpack
    build-parameters:
      builder: npm-ci
    provides:
      - name: srv-api # required by consumers of CAP services (e.g. approuter)
        properties:
          srv-url: ${default-url}
    requires:
      - name: authenticator_service
      - name: db-sfadb
      - name: destination
      - name: Connectivity-srv

  # Approuter
  - name: sfadb-approuter
    type: nodejs
    path: app/ # from cds.env.folders. Consider also cds.env.build.target -&amp;gt; gen/app
    parameters:
      keep-existing-routes: true
      disk-quota: 512MB
      memory: 512MB
    provides:
      - name: approuter-api # required by consumers of CAP services (e.g. approuter)
        properties:
          srv-url: ${default-url}
    requires:
      - name: srv-api
        group: destinations
        properties:
          name: srv-api # must be used in xs-app.json as well
          url: ~{srv-url}
          forwardAuthToken: true
      - name: authenticator_service

  # DB Deployer Module
  - name: db-deployer
    type: custom
    path: gen/db
    parameters:
      buildpacks:
        - &lt;A href="https://github.com/cloudfoundry/apt-buildpack#v0.3.0" target="test_blank"&gt;https://github.com/cloudfoundry/apt-buildpack#v0.3.0&lt;/A&gt;
        - nodejs_buildpack
      no-route: true
      no-start: true
      disk-quota: 2GB
      memory: 1024MB
      tasks:
        - name: deploy_to_postgresql #I need start script before this
          command: export JAVA_OPTS="-Xmx1g" &amp;amp;&amp;amp; chmod 755 deploy.sh &amp;amp;&amp;amp; ./deploy.sh
          disk-quota: 2GB
          memory: 1024MB
    build-parameters:
      ignore:
        - "node_modules/"
    requires:
      - name: db-sfadb

  #Content Deployer
  - name: destination-content
    type: com.sap.application.content
    requires:
      - name: authenticator_service
        parameters:
          service-key:
            name: authenticator_key
      - name: destination
        parameters:
          content-target: true
    parameters:
      content:
        subaccount:
          destinations:
            - Authentication: OAuth2UserTokenExchange
              Name: authenticator_service
              ServiceInstanceName: authenticator_service
              ServiceKeyName: authenticator_key
              sap.cloud.service: sfa.service
          existing_destinations_policy: update
    build-parameters:
      no-source: true

resources:

  - name: authenticator_service
    type: org.cloudfoundry.managed-service
    parameters:
      service-name: authenticator_service
      service: xsuaa
      service-plan: application
      path: ./xs-security.json
      config:
        xsappname: auth-${space}
        tenant-mode: dedicated

  - name: destination
    type: org.cloudfoundry.managed-service
    requires:
      - name: srv-api
      - name: approuter-api
    parameters:
      service: destination
      service-name: destination-service
      service-plan: lite
      config:
        init_data:
          subaccount:
            existing_destinations_policy: ignore
            destinations:
              - Name: sfadb_srv_api
                Description: CAP sample service
                Authentication: NoAuthentication
                ProxyType: Internet
                Type: HTTP
                URL: ~{srv-api/srv-url}
                HTML5.DynamicDestination: true
                HTML5.ForwardAuthToken: true
              - Name: ZSFA2
                Authentication: BasicAuthentication
                ProxyType: Internet
                Type: HTTP
                URL: DUMMY_URL
                User: sample
                Password: sample
                HTML5.Timeout: true
              - Name: ZSFA2_SOAP
                Authentication: BasicAuthentication
                ProxyType: OnPremise
                Type: HTTP
                URL: DUMMY_URL
                User: sample
                Password: sample
                sap-client: 200
                TrustAll: false

  - name: db-sfadb
    parameters:
      path: ./pg-options.json
      service: postgresql-db
      #service-plan: trial # BTP trial
      service-plan: free    # BTP CPEA - free
      #service-plan: standard # BTP CPEA - standard (not free)
      service-tags:
        - plain
      skip-service-updates:
        parameters: true
    type: org.cloudfoundry.managed-service

  - name: Connectivity-srv
    type: org.cloudfoundry.managed-service
    parameters:
      service: connectivity
      service-plan: lite&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;package.json&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;{
    "name": "sfadb",
    "version": "0.0.1",
    "description": "Shared DB for sfa apps",
    "repository": "**",
    "license": "UNLICENSED",
    "private": true,
    "dependencies": {
        "@sap-cloud-sdk/connectivity": "^2.14.0",
        "@sap-cloud-sdk/http-client": "^2.13.0",
        "@sap/cds": "6.5.0",
        "@sap/cds-dk": "^6.4.0",
        "@sap/jobs-client": "^1.7.30",
        "@sap/xsenv": "^3.3.2",
        "@sap/xssec": "^3",
        "cds-dbm": "0.1.2",
        "cds-pg": "0.1.33",
        "child_process": "^1.0.2",
        "express": "^4",
        "fs-extra": "11.1.1",
        "mbt": "^1.2.23",
        "passport": "^0",
        "request": "^2.88.2",
        "uuid": "^9.0.0",
        "xml2js": "^0.4.23"
    },
    "devDependencies": {
        "@sap/cds-odata-v2-adapter-proxy": "latest",
        "@sap/ux-specification": "^1.102.14",
        "rimraf": "^3.0.2",
        "sqlite3": "^5.0.4",
        "ui5-middleware-livereload": "^0.7.0"
    },
    "scripts": {
        "start": "cds run",
        "watch-ui": "cds watch --open tso/webapp/index.html?sap-ui-xx-viewCache=false"
    },
    "engines": {
        "node": "^16.15"
    },
    "eslintConfig": {
        "extends": "eslint:recommended",
        "env": {
            "es2020": true,
            "node": true,
            "jest": true,
            "mocha": true
        },
        "globals": {
            "SELECT": true,
            "INSERT": true,
            "UPDATE": true,
            "DELETE": true,
            "CREATE": true,
            "DROP": true,
            "CDL": true,
            "CQL": true,
            "CXL": true,
            "cds": true
        },
        "rules": {
            "no-console": "off",
            "require-atomic-updates": "off"
        }
    },
    "cds": {
        "i18n": {
            "defaultLocales": [
                "en",
                "it",
                "de"
            ],
            "for_sqlite": [
                "en",
                "it",
                "de"
            ]
        },
        "requires": {
            "ZSFA_ODV4": {
                "kind": "odata",
                "csrf": true,
                "csrfInBatch": true,
                "credentials": {
                    "path": "**",
                    "destination": "ZSFA2"
                }
            },
            "[production]": {
                "db": {
                    "dialect": "plain",
                    "kind": "database"
                },
                "database": {
                    "dialect": "plain",
                    "impl": "cds-pg",
                    "model": [
                        "srv"
                    ],
                    "credentials": {
                        "host": "localhost",
                        "port": 5432,
                        "database": "devtoberfest",
                        "user": "**",
                        "password": "**"
                    }
                }
            },
            "auth": {
                "kind": "xsuaa"
            },
            "db": {
                "dialect": "plain",
                "kind": "database",
                "credentials": {
                    "host": "localhost",
                    "port": 5432,
                    "database": "sfadb",
                    "user": "**",
                    "password": "**"
                }
            },
            "database": {
                "dialect": "plain",
                "impl": "cds-pg",
                "model": [
                    "srv"
                ],
                "credentials": {
                    "host": "localhost",
                    "port": 5432,
                    "database": "sfadb",
                    "user": "**",
                    "password": "**"
                }
            },
            "approuter": {
                "kind": "cloudfoundry"
            },
            "API_CV_ATTACHMENT_SRV": {
                "kind": "odata-v2",
                "credentials": {
                    "path": "**",
                    "destination": "ZSFA2"
                }
            }
        },
        "migrations": {
            "db": {
                "schema": {
                    "default": "public",
                    "clone": "_cdsdbm_clone",
                    "reference": "_cdsdbm_ref"
                },
                "deploy": {
                    "tmpFile": "tmp/_autodeploy.json",
                    "undeployFile": "dbm/undeploy.json"
                }
            }
        },
        "build": {
            "tasks": [
                {
                    "for": "node-cf",
                    "src": "srv",
                    "options": {
                        "model": [
                            "db",
                            "srv",
                            "app"
                        ]
                    }
                },
                {
                    "use": "cds-dbm/dist/build/postgres-cf",
                    "for": "postgres-cf",
                    "src": "db",
                    "options": {
                        "deployCmd": "npx cds-dbm deploy --load-via delta"
                    }
                }
            ]
        }
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 09:11:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/start-a-js-script-before-deployment/qaq-p/12777228</guid>
      <dc:creator>former_member824324</dc:creator>
      <dc:date>2023-08-04T09:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Start a js script before deployment</title>
      <link>https://community.sap.com/t5/technology-q-a/start-a-js-script-before-deployment/qaa-p/12777229#M4796993</link>
      <description>&lt;P&gt;DB deployment happens in a task run in cloud foundry run in DB deployer module/application. I suppose your script will run as part of the same task. If so, you need to package your script in the  DB deployer module/application. I suppose it has some influence over what deploy.sh does.  You can then adjust the command of the task to run your script too; just add it the command before `&amp;amp;&amp;amp; ./deploy.sh`&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 14:09:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/start-a-js-script-before-deployment/qaa-p/12777229#M4796993</guid>
      <dc:creator>Dinu</dc:creator>
      <dc:date>2023-08-04T14:09:02Z</dc:date>
    </item>
  </channel>
</rss>

