diff --git a/guides/databases/postgres.md b/guides/databases/postgres.md index 3d312a3eb..ae914d5b4 100644 --- a/guides/databases/postgres.md +++ b/guides/databases/postgres.md @@ -1,40 +1,20 @@ ---- -impl-variants: true ---- # Using PostgreSQL -
- This guide focuses on the new PostgreSQL Service provided through *[@cap-js/postgres](https://www.npmjs.com/package/@cap-js/postgres)*, which is based on the same new database services architecture as the new [SQLite Service](./sqlite). -*Learn about migrating from the former `cds-pg` in the [Migration](#migration) chapter.*{.learn-more} - -
- -
- CAP Java 3 is tested on [PostgreSQL](https://www.postgresql.org/) 16 and most CAP features are supported on PostgreSQL. -[Learn more about features and limitations of using CAP with PostgreSQL](../../java/cqn-services/persistence-services#postgresql){.learn-more} -
+*Learn about migrating from the former `cds-pg` in the [Migration](#migration-from-cds-pg-in-node-js) chapter.*{.learn-more} +[Learn more about features and limitations of using CAP Java with PostgreSQL.](../../java/cqn-services/persistence-services#postgresql){.learn-more} - [[toc]] ## Setup & Configuration -
- -Run this to use [PostgreSQL](https://www.postgresql.org/) for production: - -
- -
- To run CAP Java on PostgreSQL, add a Maven dependency to the PostgreSQL feature in `srv/pom.xml`: ```xml @@ -45,21 +25,16 @@ To run CAP Java on PostgreSQL, add a Maven dependency to the PostgreSQL feature ``` -In order to use the CDS tooling with PostgreSQL, you also need to install the module `@cap-js/postgres`: - -
+For CAP Node.js projects, and for CAP Java in order to use the CDS tooling with PostgreSQL, you also need to install the module `@cap-js/postgres`: ```sh npm add @cap-js/postgres ``` -
- -After that, you can use the `cds deploy` command to [deploy](#using-cds-deploy) to a PostgreSQL database or to [create a DDL script](#using-liquibase-java) for PostgreSQL. +After that, you can use the `cds deploy` command to [deploy](#using-cds-deploy) to a PostgreSQL database or to [create a DDL script](#using-liquibase-in-cap-java) for PostgreSQL. -
-### Auto-Wired Configuration {.node} +### Auto-Wired Configuration in Node.js The `@cap-js/postgres` package uses `cds-plugin` technique to auto-configure your application and use a PostgreSQL database for production. @@ -84,7 +59,7 @@ Output: To connect to a PostgreSQL offering from the cloud provider in Production, leverage the [PostgreSQL on SAP BTP, hyperscaler option](https://discovery-center.cloud.sap/serviceCatalog/postgresql-hyperscaler-option). For local development and testing convenience, you can run PostgreSQL in a [docker container](#using-docker). -
+### CAP Java on SAP BTP To consume a PostgreSQL instance from a CAP Java application running on SAP BTP, consider the following: @@ -112,7 +87,6 @@ modules: ::: > `BOOKSHOP-PG-DB` is the real PostgreSQL service instance name in this example. -
### Using Docker @@ -141,27 +115,17 @@ You can use Docker to run a PostgreSQL database locally as follows: docker-compose -f pg.yml up -d ``` -
- -::: tip +::: tip Testcontainer in CAP Java using Spring Boot With the introduction of [Testcontainers support](https://spring.io/blog/2023/06/23/improved-testcontainers-support-in-spring-boot-3-1) in Spring Boot 3.1, you can create PostgreSQL containers on the fly for local development or testing purposes. ::: -
- ## Service Bindings You need a service binding to connect to the PostgreSQL database. In the cloud, use given techniques to bind a cloud-based instance of PostgreSQL to your application. -
- -For local development provide the credentials using a suitable [`cds env`](../../node.js/cds-env) technique, like one of the following. - -
- -### Configure Connection Data {.java} +### Configure Connection Data in CAP Java If a PostgreSQL service binding exists, the corresponding `DataSource` is auto-configured. @@ -181,11 +145,11 @@ spring: ::: To start the application with the new profile `postgres-docker`, the `spring-boot-maven-plugin` can be used: `mvn spring-boot:run -Dspring-boot.run.profiles=postgres-docker`. -[Learn more about the configuration of a PostgreSQL database](../../java/cqn-services/persistence-services#postgresql-1){ .learn-more} +[Learn more about the configuration of a PostgreSQL database.](../../java/cqn-services/persistence-services#postgresql-1){ .learn-more} -### Service Bindings for CDS Tooling {.java} +### Service Bindings for CDS Tooling in CAP Java -#### Using Defaults with `[pg]` Profile {.java} +#### Using Defaults with `[pg]` Profile `@cds-js/postgres` comes with a set of default credentials under the profile `[pg]` that matches the defaults used in the [docker setup](#using-docker). So, if you stick to these defaults you can skip to deploying your database with: @@ -193,7 +157,7 @@ To start the application with the new profile `postgres-docker`, the `spring-boo cds deploy --profile pg ``` -#### In Your Private `.cdsrc-private.json` {.java} +#### In Your Private `.cdsrc-private.json` If you don't use the default credentials and want to use just `cds deploy`, you need to configure the service bindings (connection data) for the CDS tooling. Add the connection data to your private `.cdsrc-private.json`: @@ -214,7 +178,9 @@ If you don't use the default credentials and want to use just `cds deploy`, you } ``` -### Configure Service Bindings {.node} +### Configure Service Bindings in Node.js + +For local development provide the credentials using a suitable [`cds env`](../../node.js/cds-env) technique, like one of the following. #### Using Defaults with `[pg]` Profile @@ -515,7 +481,7 @@ to your database! ::: -## Using Liquibase (Java) +## Using Liquibase in CAP Java In CAP Java projects you can also use [Liquibase](https://www.liquibase.org/) to control when, where, and how database changes are deployed. Liquibase lets you define database changes [in an SQL file](https://docs.liquibase.com/change-types/sql-file.html), use `cds deploy` to quickly generate DDL scripts which can be used by Liquibase. @@ -617,7 +583,7 @@ If the changes in the model could lead to data loss, an error is raised. ::: -## Migration { .node } +## Migration from cds-pg in Node.js Thanks to CAP's database-agnostic cds.ql API, we're confident that the new PostgreSQL service comes without breaking changes. diff --git a/guides/databases/schema-evolution.md b/guides/databases/schema-evolution.md index 78c21f27b..b32668e0c 100644 --- a/guides/databases/schema-evolution.md +++ b/guides/databases/schema-evolution.md @@ -198,4 +198,4 @@ For Java-based CAP projects, you can also use [Liquibase](https://www.liquibase. Please be aware that Liquibase [changed its license to Functional Source License (FSL)](https://www.liquibase.com/blog/liquibase-community-for-the-future-fsl) with release 5.0. You need to check if this license is compatible with your application. ::: -Learn more about that in the [PostgreSQL](postgres.md) guide, section [Using Liquibase (Java)](postgres#using-liquibase-java). +Learn more about that in the [PostgreSQL](postgres.md) guide, section [Using Liquibase (Java)](postgres#using-liquibase-in-cap-java). diff --git a/java/cqn-services/persistence-services.md b/java/cqn-services/persistence-services.md index 734e82fec..f08744565 100644 --- a/java/cqn-services/persistence-services.md +++ b/java/cqn-services/persistence-services.md @@ -184,7 +184,7 @@ cds add postgres ``` ::: warning -Automatic schema deployment isn't suitable for productive use. Consider using production-ready tools like Flyway or Liquibase. See more on that in the [Database guide for PostgreSQL](../../guides/databases/postgres#using-liquibase-java) +Automatic schema deployment isn't suitable for productive use. Consider using production-ready tools like Flyway or Liquibase. See more on that in the [Database guide for PostgreSQL](../../guides/databases/postgres#using-liquibase-in-cap-java) ::: #### Configure the Connection Data Explicitly { #postgres-connection } diff --git a/java/event-queues.md b/java/event-queues.md index 3211862e6..c3261d79f 100644 --- a/java/event-queues.md +++ b/java/event-queues.md @@ -524,7 +524,7 @@ A startup log entry shows the configured version: 2024-12-19T11:21:33.253+01:00 INFO 3420 --- [main] cds.services.impl.utils.BuildInfo : application.deployment.version: 1.0.0-SNAPSHOT ``` -To bypass the version check for a specific custom outbox, set [`cds.outbox.services.MyCustomOutbox.checkVersion: false`](./developing-applications/properties#cds-outbox-services--checkVersion). +To bypass the version check for a specific custom outbox, set [`cds.outbox.services.MyCustomOutbox.checkVersion: false`](./developing-applications/properties#cds-outbox-services--checkversion). ## Troubleshooting