From 0b12697d3df1578f27535fe3ac1ec3427eb595de Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Wed, 29 Nov 2023 12:25:51 +0100 Subject: [PATCH] Upgrade postgresql to 16.1 see https://medium.com/@dmitry.romanoff/postgresql-version-15-error-permission-denied-for-schema-public-dc8285c41e00 --- .examples/docker-compose/docker-compose.yml | 2 +- README.md | 2 +- docker-compose.yml | 2 +- .../zeiterfassung/TestContainersBase.java | 13 ++---- .../TestPostgreSQLContainer.java | 40 +++++++++++++++++++ src/test/resources/init-user-db.sql | 1 + 6 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 src/test/java/de/focusshift/zeiterfassung/TestPostgreSQLContainer.java diff --git a/.examples/docker-compose/docker-compose.yml b/.examples/docker-compose/docker-compose.yml index 9163e89e0..69b605a10 100644 --- a/.examples/docker-compose/docker-compose.yml +++ b/.examples/docker-compose/docker-compose.yml @@ -38,7 +38,7 @@ services: condition: service_started postgres: - image: postgres:9.6 + image: postgres:16.1 ports: - '5432:5432' environment: diff --git a/README.md b/README.md index 17818fd82..ad906ce5d 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Wenn du mehr Informationen und Bilder über dieses Projekt sehen möchtest dann * [JDK 21](https://adoptium.net) * [Docker 20.10+](https://www.docker.com/) -* [PostgreSQL 9.6+](#database) +* [PostgreSQL 16.1+](#database) * [E-Mail-Server](#e-mail-server) * [OpenID Connect identity provider](#openid-connect-identity-provider) diff --git a/docker-compose.yml b/docker-compose.yml index 991b007ab..714e321cf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.8' services: postgres: - image: postgres:9.6 + image: postgres:16.1 environment: POSTGRES_DB: zeiterfassung POSTGRES_USER: admin_user diff --git a/src/test/java/de/focusshift/zeiterfassung/TestContainersBase.java b/src/test/java/de/focusshift/zeiterfassung/TestContainersBase.java index 2cc63b7ea..3b5e22cb0 100644 --- a/src/test/java/de/focusshift/zeiterfassung/TestContainersBase.java +++ b/src/test/java/de/focusshift/zeiterfassung/TestContainersBase.java @@ -8,16 +8,11 @@ public abstract class TestContainersBase { - static final PostgreSQLContainer postgres = new PostgreSQLContainer<>(IMAGE + ":9.6") - .withDatabaseName("zeiterfassung") - .withInitScript("init-user-db.sql"); + static final TestPostgreSQLContainer postgre = new TestPostgreSQLContainer(); @DynamicPropertySource - static void postgresDBProperties(DynamicPropertyRegistry registry) { - postgres.start(); - registry.add("spring.datasource.url", postgres::getJdbcUrl); - registry.add("spring.liquibase.parameters.database", postgres::getDatabaseName); - registry.add("admin.datasource.username", postgres::getUsername); - registry.add("admin.datasource.password", postgres::getPassword); + static void registerProperties(DynamicPropertyRegistry registry) { + postgre.start(); + postgre.configureSpringDataSource(registry); } } diff --git a/src/test/java/de/focusshift/zeiterfassung/TestPostgreSQLContainer.java b/src/test/java/de/focusshift/zeiterfassung/TestPostgreSQLContainer.java new file mode 100644 index 000000000..d04768c9b --- /dev/null +++ b/src/test/java/de/focusshift/zeiterfassung/TestPostgreSQLContainer.java @@ -0,0 +1,40 @@ +package de.focusshift.zeiterfassung; + +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.PostgreSQLContainer; + +public class TestPostgreSQLContainer extends PostgreSQLContainer { + + private static final String VERSION = "16.1"; + + public TestPostgreSQLContainer() { + super(IMAGE + ":" + VERSION); + this.withDatabaseName("zeiterfassung"); + this.withCommand("--max_connections=1000", "--shared_buffers=240MB"); + this.withInitScript("init-user-db.sql"); + } + + /** + * Sets the spring datasource configuration properties. + * + *

Usage:

+ *

+     * static final TestPostgreContainer postgre = new TestPostgreContainer();
+     * @DynamicPropertySource
+     * static void setupDataSource(DynamicPropertySource registry) {
+     *     postgre.start();
+     *     postgre.configureSpringDataSource(registry);
+     * }
+     * 
+     * 
+ * + * @param registry + */ + public void configureSpringDataSource(DynamicPropertyRegistry registry) { + registry.add("spring.datasource.url", this::getJdbcUrl); + registry.add("spring.liquibase.parameters.database", this::getDatabaseName); + registry.add("admin.datasource.username", this::getUsername); + registry.add("admin.datasource.password", this::getPassword); + } +} diff --git a/src/test/resources/init-user-db.sql b/src/test/resources/init-user-db.sql index adb40a16b..a686d3e37 100644 --- a/src/test/resources/init-user-db.sql +++ b/src/test/resources/init-user-db.sql @@ -1,4 +1,5 @@ CREATE USER "app_user" WITH PASSWORD 'app_password'; +GRANT ALL ON SCHEMA public TO "app_user"; GRANT CONNECT ON DATABASE "zeiterfassung" TO "app_user"; ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON TABLES TO "app_user"; ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT USAGE ON SEQUENCES TO "app_user";