From: Kai Moritz Date: Sun, 25 Oct 2020 15:34:05 +0000 (+0100) Subject: Added a profile, that starts the app with a PostgreSQL-DB X-Git-Tag: part-1~3 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=d31cfb6720f03a4fec0ae8c660d2e10826d0b69f;p=demos%2Fspring%2Fdata-jdbc 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" --- 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/V1__Table_users.sql deleted file mode 100644 index 5e3590b..0000000 --- a/src/main/resources/db/migration/V1__Table_users.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE TABLE users (id BIGINT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(255), created TIMESTAMP, logged_in BIT); diff --git a/src/main/resources/db/migration/h2/V1__Table_users.sql b/src/main/resources/db/migration/h2/V1__Table_users.sql new file mode 100644 index 0000000..5e3590b --- /dev/null +++ b/src/main/resources/db/migration/h2/V1__Table_users.sql @@ -0,0 +1 @@ +CREATE TABLE users (id BIGINT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(255), created TIMESTAMP, logged_in BIT); 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;