From d31cfb6720f03a4fec0ae8c660d2e10826d0b69f Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 25 Oct 2020 16:34:05 +0100 Subject: [PATCH] Added a profile, that starts the app with a PostgreSQL-DB * Added the dependency for the PostgreSQL-driver * Added the new profile * Configured Flyway to apply db-specific SQL * Added a PostgreSQL-DB to the setup for Docker Compose as "postgres" * Added a named volume for the data of the service "postgres" * Selected the new profile "prod" for the service "jdbc" --- docker-compose.yml | 16 ++++++++++++++++ pom.xml | 4 ++++ src/main/resources/application.yml | 15 +++++++++++++++ .../db/migration/{ => h2}/V1__Table_users.sql | 0 .../db/migration/postgres/V1__Table_users.sql | 3 +++ 5 files changed, 38 insertions(+) rename src/main/resources/db/migration/{ => h2}/V1__Table_users.sql (100%) create mode 100644 src/main/resources/db/migration/postgres/V1__Table_users.sql diff --git a/docker-compose.yml b/docker-compose.yml index 79f5d1c..b7e85f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,3 +5,19 @@ services: image: jdbc:latest ports: - 8080:8080 + environment: + spring.profiles.active: prod + + postgres: + image: postgres:13 + ports: + - 5432:5432 + environment: + POSTGRES_USER: outbox + POSTGRES_PASSWORD: outbox + POSTGRES_DB: outbox + volumes: + - pgdata:/var/lib/postgresql/data/ + +volumes: + pgdata: diff --git a/pom.xml b/pom.xml index 82dc5dd..b5d3209 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,10 @@ com.h2database h2 + + org.postgresql + postgresql + org.springframework.boot spring-boot-starter-test diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7ea719a..0927e14 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,3 +3,18 @@ management: web: exposure: include: "*" + +spring: + flyway: + locations: classpath:db/migration/h2 + +--- + +spring: + profiles: prod + datasource: + url: jdbc:postgresql://postgres:5432/outbox + username: outbox + password: outbox + flyway: + locations: classpath:db/migration/postgres diff --git a/src/main/resources/db/migration/V1__Table_users.sql b/src/main/resources/db/migration/h2/V1__Table_users.sql similarity index 100% rename from src/main/resources/db/migration/V1__Table_users.sql rename to src/main/resources/db/migration/h2/V1__Table_users.sql diff --git a/src/main/resources/db/migration/postgres/V1__Table_users.sql b/src/main/resources/db/migration/postgres/V1__Table_users.sql new file mode 100644 index 0000000..39b0f2d --- /dev/null +++ b/src/main/resources/db/migration/postgres/V1__Table_users.sql @@ -0,0 +1,3 @@ +CREATE SEQUENCE users_id_seq; +CREATE TABLE users (id BIGINT PRIMARY KEY NOT NULL DEFAULT NEXTVAL('users_id_seq'), username VARCHAR(255), created TIMESTAMP, logged_in BOOLEAN); +ALTER SEQUENCE users_id_seq OWNED BY users.id; -- 2.20.1