Skip to content

Commit

Permalink
Upgrade postgresql to 16.1 (#475)
Browse files Browse the repository at this point in the history
closes #474 

Here are some things you should have thought about:

**Multi-Tenancy**
- [ ] Extended new entities with `AbstractTenantAwareEntity`?
- [ ] New entity added to `TenantAwareDatabaseConfiguration`?
- [ ] Tested with `dev-multitenant` profile?

<!--

Thanks for contributing to the zeiterfassung.
Please review the following notes before submitting you pull request.

Please look for other issues or pull requests which already work on this
topic. Is somebody already on it? Do you need to synchronize?

# Security Vulnerabilities

🛑 STOP! 🛑 If your contribution fixes a security vulnerability, please do
not submit it.
Instead, please write an E-Mail to [email protected] with all the
information
to recreate the security vulnerability.

# Describing Your Changes

If, having reviewed the notes above, you're ready to submit your pull
request, please
provide a brief description of the proposed changes.

If they:
🐞 fix a bug, please describe the broken behaviour and how the changes
fix it.
    Please label with 'type: bug' and 'status: new'
    
🎁 make an enhancement, please describe the new functionality and why you
believe it's useful.
    Please label with 'type: enhancement' and 'status: new'
 
If your pull request relates to any existing issues,
please reference them by using the issue number prefixed with #.

-->
  • Loading branch information
derTobsch authored Nov 29, 2023
2 parents cd4c54c + 0b12697 commit 4eee2be
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 4eee2be

Please sign in to comment.