Skip to content

Commit 92f0b14

Browse files
GloriaGloria
authored andcommitted
Added postgres DB
1 parent bdf0609 commit 92f0b14

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

backend/pom.xml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,43 @@
3030
<java.version>17</java.version>
3131
</properties>
3232
<dependencies>
33+
<!-- JPA + Hibernate -->
3334
<dependency>
3435
<groupId>org.springframework.boot</groupId>
3536
<artifactId>spring-boot-starter-data-jpa</artifactId>
37+
<exclusions>
38+
<exclusion>
39+
<groupId>org.flywaydb</groupId>
40+
<artifactId>flyway-core</artifactId>
41+
</exclusion>
42+
</exclusions>
3643
</dependency>
44+
<!-- PostgreSQL Driver -->
45+
<dependency>
46+
<groupId>org.postgresql</groupId>
47+
<artifactId>postgresql</artifactId>
48+
<scope>runtime</scope>
49+
</dependency>
50+
<!-- Flyway for postgresql 15 -->
51+
<dependency>
52+
<groupId>org.flywaydb</groupId>
53+
<artifactId>flyway-core</artifactId>
54+
<version>10.15.0</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.flywaydb</groupId>
58+
<artifactId>flyway-database-postgresql</artifactId>
59+
</dependency>
60+
<!-- Spring Boot starter -->
3761
<dependency>
3862
<groupId>org.springframework.boot</groupId>
3963
<artifactId>spring-boot-starter-web</artifactId>
4064
</dependency>
65+
66+
<dependency>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-starter-data-jpa</artifactId>
69+
</dependency>
4170
<dependency>
4271
<groupId>org.springframework.boot</groupId>
4372
<artifactId>spring-boot-starter-security</artifactId>
@@ -53,11 +82,6 @@
5382
<scope>runtime</scope>
5483
<optional>true</optional>
5584
</dependency>
56-
<dependency>
57-
<groupId>org.postgresql</groupId>
58-
<artifactId>postgresql</artifactId>
59-
<scope>runtime</scope>
60-
</dependency>
6185
<dependency>
6286
<groupId>org.springframework.boot</groupId>
6387
<artifactId>spring-boot-starter-test</artifactId>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
spring.application.name=backend
1+
spring.application.name=backend
2+
spring.flyway.enabled=true
3+
spring.flyway.locations=classpath:db/migration
4+
spring.flyway.baseline-on-migrate=true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE users (
2+
id SERIAL PRIMARY KEY,
3+
username VARCHAR(255) NOT NULL,
4+
email VARCHAR(255) UNIQUE NOT NULL
5+
);

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ services:
2323
- postgres
2424
volumes:
2525
- pgadmin-data:/var/lib/pgadmin
26+
- ./pgadmin/servers.json:/pgadmin4/servers.json
27+
- ./pgadmin/pgpass:/pgpass
28+
entrypoint:
29+
- /bin/sh
30+
- -c
31+
- |
32+
echo "pgdb:5432:appdb:appuser:secret" > /pgpass
33+
chmod 600 /pgpass
34+
/entrypoint.sh
2635
2736
backend:
2837
build:

pgadmin/servers.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Servers": {
3+
"1": {
4+
"Name": "Grocer Compare DB",
5+
"Group": "Servers",
6+
"Host": "pgdb",
7+
"Port": 5432,
8+
"MaintenanceDB": "appdb",
9+
"Username": "appuser",
10+
"SSLMode": "prefer",
11+
"PassFile": "/pgpass"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)