Skip to content

Commit

Permalink
Upgrade postgresql to 16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
derTobsch committed Nov 29, 2023
1 parent cd4c54c commit 0b12697
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .examples/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ services:
condition: service_started

postgres:
image: postgres:9.6
image: postgres:16.1
ports:
- '5432:5432'
environment:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<TestPostgreSQLContainer> {

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.
*
* <p>Usage:</p>
* <pre><code>
* static final TestPostgreContainer postgre = new TestPostgreContainer();
* &#64;DynamicPropertySource
* static void setupDataSource(DynamicPropertySource registry) {
* postgre.start();
* postgre.configureSpringDataSource(registry);
* }
* </code>
* </pre>
*
* @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);
}
}
1 change: 1 addition & 0 deletions src/test/resources/init-user-db.sql
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 0b12697

Please sign in to comment.