Added a profile, that starts the app with a PostgreSQL-DB
authorKai Moritz <kai@juplo.de>
Sun, 25 Oct 2020 15:34:05 +0000 (16:34 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 7 Feb 2021 13:49:20 +0000 (14:49 +0100)
* 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
pom.xml
src/main/resources/application.yml
src/main/resources/db/migration/V1__Table_users.sql [deleted file]
src/main/resources/db/migration/h2/V1__Table_users.sql [new file with mode: 0644]
src/main/resources/db/migration/postgres/V1__Table_users.sql [new file with mode: 0644]

index 79f5d1c..b7e85f2 100644 (file)
@@ -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 (file)
--- a/pom.xml
+++ b/pom.xml
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
      </dependency>
+     <dependency>
+       <groupId>org.postgresql</groupId>
+       <artifactId>postgresql</artifactId>
+     </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
index 7ea719a..0927e14 100644 (file)
@@ -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 (file)
index 5e3590b..0000000
+++ /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 (file)
index 0000000..5e3590b
--- /dev/null
@@ -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 (file)
index 0000000..39b0f2d
--- /dev/null
@@ -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;