Skip to content

Commit a664321

Browse files
authored
Give more flexibility for jdbc url: schemas, query parameters, dbname prefix (#14)
1 parent 3e4de4e commit a664321

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/main/resources/application.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spring:
99
max-request-size: 103MB
1010

1111
datasource:
12-
url: ${dbApi}:${dbVendor}://${hostPort}/${dbName}${query}
12+
url: ${dbUrl}
1313
username: ${login}
1414
password: ${password}
1515

@@ -54,6 +54,14 @@ network-store-server:
5454
preloading-strategy: COLLECTION
5555
base-uri: http://localhost:8080/
5656

57+
# this structure is shared among all microservices, if you change it, change it everywhere
58+
# customQuery allows a microservice to set query parameters specific to itself
59+
# if customQuery is empty, set queryBegin to "?", otherwise set it to "&"
60+
# this allow the user to add additional query elements common to all microservices
61+
# and using the appropriate leading character depending on whether the microsevice
62+
# uses custom query parameters
63+
queryBegin: '?'
64+
customQuery:
5765
dbName: dynamicmappings
5866
dbApi: jdbc
5967

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1+
# This file is meant to be overriden in deployments by a single file in all microservices
2+
# if you change its structure, change it in all microservices.
3+
# values here can be overriden for all microservices in this common file,
4+
# or in specific microservices in its specific application.yml file
5+
6+
# default values
17
dbVendor=postgresql
28
host=localhost
39
port=5432
410
query=
511
login=postgres
612
password=postgres
7-
hostPort=${host}:${port}
13+
# use this if you want to use the preferred db name of the microservice,
14+
# but with multiple variants, like for different environments
15+
dbPrefix=
16+
17+
# these allow to customize the url construction a bit for weird jdbc connection strings
18+
hostPort=://${host}:${port}/
19+
dbProtocolHost=${dbApi}:${dbVendor}${hostPort}
20+
21+
dbFullName=${dbPrefix}${dbName}
22+
finalQuery=${customQuery}${query}
23+
dbManyBasesPath=${dbFullName}${finalQuery}
24+
dbManySchemasPath=${commonDbName}?currentSchema=${dbFullName}${finalQuery}
25+
26+
dbUrlManyBases=${dbProtocolHost}${dbManyBasesPath}
27+
dbUrlManySchemas=${dbProtocolHost}${dbManySchemasPath}
28+
29+
# leave this if you want 1 database per microservice
30+
dbUrl=${dbUrlManyBases}
31+
# use this if you want 1 database for all microservice, each in a schema
32+
# and set commonDbName
33+
#dbUrl=${dbUrlManySchemas}

src/test/resources/application-default.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ logging:
1616

1717
dbVendor: h2:mem
1818
query: ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
19-
hostPort:
19+
hostPort: ":"
2020

2121
backing-services:
2222
case:

0 commit comments

Comments
 (0)