Skip to content

Commit afb1d69

Browse files
committed
Merge databases into single
1 parent 4d68341 commit afb1d69

File tree

9 files changed

+43
-68
lines changed

9 files changed

+43
-68
lines changed

backend/authik/src/main/resources/application.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ spring:
44
application:
55
name: authik
66
datasource:
7-
url: jdbc:postgresql://authik-database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
7+
url: jdbc:postgresql://database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
88
username: ${POSTGRES_USER}
99
password: ${POSTGRES_PASSWORD}
1010
r2dbc:
11-
url: r2dbc:postgresql://authik-database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
11+
url: r2dbc:postgresql://database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
1212
username: ${POSTGRES_USER}
1313
password: ${POSTGRES_PASSWORD}
1414
security:

backend/config/env/.env

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
ITMO_DATING_TOKEN_SIGN_KEY_PUBLIC="RSA:MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEArnKw3YcR3WJeLW64J6gc+8dT/ptl4Oi1kdfgib1EQBJmiNVmzgx6hnmf60MhTCbPHeKhbBKzozyFlboO32Aqx5Nfb0UAU2ssl99tuNi8R2VsYby6wkog58GgFidffKohdhWjOZaa3rBNI1D8CQXckk5WW4eFbonB6Vo84OLsebW5CX9ob8bCsJBX2iZYwS+WNCluUMFgxRyaLuyhtyKp0YRa7oje7iu3EXiLnaXTAFhGSP+iK6GxMUPORvGZYfJ7z+tpj6OYQId5cwYD/+5EXFM4wCkq82VDbj99mJqClpHs+1DhPP7sO/aSDM9SONXjAsMTtq27jJgdvEADpd6pHtwv/tHv1PsRS6DiQYFQSx5egc48JEiVDsBkMy3TzOmvf2dAU1KLWImNSwCybnwQiBhoRr2xPuUB6gNwyrUM8gSiX5HfK9pPX2LueberFzBYnzi8yR1phkLlqfvMZn9q6uRp9ysrtsw2tGf+Wn8BlbAoq3W8hD8ufr5pR03zHGvnAgMBAAE="
22
ITMO_DATING_KEY_STORE_PASSWORD="testing-keystore-password"
33

4+
ITMO_DATING_POSTGRES_DB="postgres"
5+
ITMO_DATING_POSTGRES_USER="postgres"
6+
ITMO_DATING_POSTGRES_PASSWORD="postgres"
7+
48
ITMO_DATING_AUTHIK_POSTGRES_DB="postgres"
59
ITMO_DATING_AUTHIK_POSTGRES_USER="postgres"
610
ITMO_DATING_AUTHIK_POSTGRES_PASSWORD="postgres"

backend/consul/config/consul.hcl

+5-29
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,13 @@ ca_file = "/consul/config/itmo-dating-backend-ca.crt"
2828

2929
services = [
3030
{
31-
name = "authik-database"
32-
address = "authik-database"
31+
name = "database"
32+
address = "database"
3333
port = 5432
3434
check = {
35-
id = "authik-database-check"
36-
name = "Authik PostgreSQL Health Check"
37-
tcp = "authik-database:5432"
38-
interval = "10s"
39-
timeout = "1s"
40-
}
41-
},
42-
{
43-
name = "matchmaker-database"
44-
address = "matchmaker-database"
45-
port = 5432
46-
check = {
47-
id = "matchmaker-database-check"
48-
name = "Matchmaker PostgreSQL Health Check"
49-
tcp = "matchmaker-database:5432"
50-
interval = "10s"
51-
timeout = "1s"
52-
}
53-
},
54-
{
55-
name = "people-database"
56-
address = "people-database"
57-
port = 5432
58-
check = {
59-
id = "people-database-check"
60-
name = "People PostgreSQL Health Check"
61-
tcp = "people-database:5432"
35+
id = "database-check"
36+
name = "PostgreSQL Health Check"
37+
tcp = "database:5432"
6238
interval = "10s"
6339
timeout = "1s"
6440
}

backend/foundation/src/main/kotlin/ru/ifmo/se/dating/spring/storage/SpringLiquibaseMigration.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import kotlin.io.path.Path
88

99
@Component
1010
class SpringLiquibaseMigration(
11+
@Value("\${spring.liquibase.liquibase-schema}")
12+
liquibaseSchema: String,
13+
1114
@Value("\${spring.liquibase.change-log}")
1215
changelog: String,
1316

@@ -23,6 +26,12 @@ class SpringLiquibaseMigration(
2326
init {
2427
val suppressClose = false
2528
SingleConnectionDataSource(url, username, password, suppressClose)
26-
.use { LiquibaseMigration(Path(changelog), it).run() }
29+
.use {
30+
LiquibaseMigration(
31+
changelog = Path(changelog),
32+
serviceTablePrefix = liquibaseSchema,
33+
source = it
34+
).run()
35+
}
2736
}
2837
}

backend/foundation/src/main/kotlin/ru/ifmo/se/dating/storage/migration/LiquibaseMigration.kt

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ru.ifmo.se.dating.storage.migration
22

33
import liquibase.Liquibase
4+
import liquibase.database.Database
45
import liquibase.database.DatabaseFactory
56
import liquibase.database.jvm.JdbcConnection
67
import liquibase.resource.ClassLoaderResourceAccessor
@@ -10,13 +11,21 @@ import kotlin.io.path.pathString
1011

1112
class LiquibaseMigration(
1213
private val changelog: Path,
14+
private val serviceTablePrefix: String,
1315
private val source: DataSource,
1416
) : DatabaseMigration {
1517
override fun run() {
1618
val resources = ClassLoaderResourceAccessor(javaClass.classLoader)
1719
source.connection.use { connection ->
1820
val database = DatabaseFactory.getInstance()
1921
.findCorrectDatabaseImplementation(JdbcConnection(connection))
22+
23+
database.databaseChangeLogTableName =
24+
"${serviceTablePrefix}_${Database.databaseChangeLogTableName}"
25+
26+
database.databaseChangeLogLockTableName =
27+
"${serviceTablePrefix}_${Database.databaseChangeLogLockTableName}"
28+
2029
Liquibase(changelog.pathString, resources, database).use {
2130
it.update("development")
2231
}

backend/foundation/src/main/resources/application-foundation.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ spring:
44
datasource:
55
driver-class-name: org.postgresql.Driver
66
liquibase:
7+
liquibase-schema: ${spring.application.name}
78
change-log: database/changelog.sql
89
server:
910
ssl:

backend/matchmaker/src/main/resources/application.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ spring:
44
application:
55
name: matchmaker
66
datasource:
7-
url: jdbc:postgresql://matchmaker-database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
7+
url: jdbc:postgresql://database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
88
username: ${POSTGRES_USER}
99
password: ${POSTGRES_PASSWORD}
1010
r2dbc:
11-
url: r2dbc:postgresql://matchmaker-database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
11+
url: r2dbc:postgresql://database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
1212
username: ${POSTGRES_USER}
1313
password: ${POSTGRES_PASSWORD}

backend/people/src/main/resources/application.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ spring:
44
application:
55
name: people
66
datasource:
7-
url: jdbc:postgresql://people-database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
7+
url: jdbc:postgresql://database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
88
username: ${POSTGRES_USER}
99
password: ${POSTGRES_PASSWORD}
1010
r2dbc:
11-
url: r2dbc:postgresql://people-database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
11+
url: r2dbc:postgresql://database-primary.dating.se.ifmo.ru:5432/${POSTGRES_DB}
1212
username: ${POSTGRES_USER}
1313
password: ${POSTGRES_PASSWORD}
1414
service:

compose.yml

+8-32
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,14 @@ services:
1313
KEY_STORE_PASSWORD: ${ITMO_DATING_KEY_STORE_PASSWORD?:err}
1414
hostname: authik-0.dating.se.ifmo.ru
1515
depends_on:
16-
authik-database:
16+
database:
1717
condition: service_healthy
1818
consul:
1919
condition: service_started
2020
authik-1:
2121
extends:
2222
service: authik-0
2323
hostname: authik-1.dating.se.ifmo.ru
24-
authik-database:
25-
image: postgres
26-
environment:
27-
POSTGRES_DB: ${ITMO_DATING_AUTHIK_POSTGRES_DB?:err}
28-
POSTGRES_USER: ${ITMO_DATING_AUTHIK_POSTGRES_USER?:err}
29-
POSTGRES_PASSWORD: ${ITMO_DATING_AUTHIK_POSTGRES_PASSWORD?:err}
30-
healthcheck:
31-
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
32-
interval: 1s
33-
timeout: 1s
34-
retries: 16
35-
hostname: authik-database-primary.dating.se.ifmo.ru
3624
matchmaker-0:
3725
image: ghcr.io/secs-dev/itmo-dating-matchmaker:latest
3826
build:
@@ -45,26 +33,14 @@ services:
4533
KEY_STORE_PASSWORD: ${ITMO_DATING_KEY_STORE_PASSWORD?:err}
4634
hostname: matchmaker-0.dating.se.ifmo.ru
4735
depends_on:
48-
matchmaker-database:
36+
database:
4937
condition: service_healthy
5038
consul:
5139
condition: service_started
5240
matchmaker-1:
5341
extends:
5442
service: matchmaker-0
5543
hostname: matchmaker-1.dating.se.ifmo.ru
56-
matchmaker-database:
57-
image: postgres
58-
environment:
59-
POSTGRES_DB: ${ITMO_DATING_MATCHMAKER_POSTGRES_DB?:err}
60-
POSTGRES_USER: ${ITMO_DATING_MATCHMAKER_POSTGRES_USER?:err}
61-
POSTGRES_PASSWORD: ${ITMO_DATING_MATCHMAKER_POSTGRES_PASSWORD?:err}
62-
healthcheck:
63-
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
64-
interval: 1s
65-
timeout: 1s
66-
retries: 16
67-
hostname: matchmaker-database-primary.dating.se.ifmo.ru
6844
people-0:
6945
image: ghcr.io/secs-dev/itmo-dating-people:latest
7046
build:
@@ -77,26 +53,26 @@ services:
7753
KEY_STORE_PASSWORD: ${ITMO_DATING_KEY_STORE_PASSWORD?:err}
7854
hostname: people-0.dating.se.ifmo.ru
7955
depends_on:
80-
people-database:
56+
database:
8157
condition: service_healthy
8258
consul:
8359
condition: service_started
8460
people-1:
8561
extends:
8662
service: people-0
8763
hostname: people-1.dating.se.ifmo.ru
88-
people-database:
64+
database:
8965
image: postgres
9066
environment:
91-
POSTGRES_DB: ${ITMO_DATING_PEOPLE_POSTGRES_DB?:err}
92-
POSTGRES_USER: ${ITMO_DATING_PEOPLE_POSTGRES_USER?:err}
93-
POSTGRES_PASSWORD: ${ITMO_DATING_PEOPLE_POSTGRES_PASSWORD?:err}
67+
POSTGRES_DB: ${ITMO_DATING_POSTGRES_DB?:err}
68+
POSTGRES_USER: ${ITMO_DATING_POSTGRES_USER?:err}
69+
POSTGRES_PASSWORD: ${ITMO_DATING_POSTGRES_PASSWORD?:err}
9470
healthcheck:
9571
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
9672
interval: 1s
9773
timeout: 1s
9874
retries: 16
99-
hostname: people-database-primary.dating.se.ifmo.ru
75+
hostname: database-primary.dating.se.ifmo.ru
10076
gateway:
10177
image: ghcr.io/secs-dev/itmo-dating-gateway:latest
10278
build:

0 commit comments

Comments
 (0)