-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
159 lines (136 loc) · 4.27 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import org.flywaydb.gradle.task.AbstractFlywayTask
plugins{
id 'java'
alias(libs.plugins.flyway)
alias(libs.plugins.jooq)
}
ext{
// <shared>
apiSvcPgUrl = "jdbc:postgresql://localhost:7432/raido"
apiSvcPgSchema = "api_svc"
/* This is a different user than what the api-svc uses, this user must
be able to create schemas, tables, etc.
In an AWS env, this is the RDS master user; locally, probably just 'postgres'
*/
apiSvcPgUser = 'postgres'
apiSvcPgPassword = ""
apiSvcMigrationHost = ""
apiSvcMigrationKey = ""
/* this is the password used by the api-svc, we need it at the gradle level
so the flyway scripts can set the password for the api_user role. */
apiSvcRolePassword = null
// non-prod, usually want to set in ~/.config/raido/api-svc-db.gradle:
// apiSvcExtraLocations=["classpath:db/env/api_user","classpath:db/env/demo"]
apiSvcExtraLocations = [""]
/* force the user to override this explicitly in their environment.
The idea is to avoid accidentally running this in prod. */
flywayCleanDisabled = true
jooqGeneratedSrcDir = 'src/main/generated-jooq'
jooqGeneratedPkg = 'au.org.raid.db.jooq'
// the config loading config :/
homeDir = System.properties['user.home']
configPath = System.getProperty("RAIDO_APISVC_DB_CONFIG_PATH",
"${homeDir}/.config/raido/api-svc-db.gradle")
// </shared>
jooqGeneratedSrcDir = 'src/main/generated-jooq'
jooqGeneratedPkg = 'au.org.raid.db.jooq'
}
/* after ext{} block so that stuff is the default, and so the config
can refer to those default values */
if( file(configPath).exists() ){
println "loading config from: ${configPath}"
apply from: configPath
}
dependencies{
runtimeOnly libs.pgjdbc
jooqGenerator libs.pgjdbc
}
compileJava {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
sourceSets{
main.java{
srcDirs += [jooqGeneratedSrcDir]
}
test.resources{
srcDirs "src/test/java"
}
}
flyway{
url = apiSvcPgUrl
user = apiSvcPgUser
password = apiSvcPgPassword
schemas = [apiSvcPgSchema,'keycloak']
failOnMissingLocations = true
locations = ['classpath:db/migration'] + apiSvcExtraLocations
placeholders = [
/* this one is really only needed when setting locations to load the
api_user script */
'apiSvcRolePassword' : apiSvcRolePassword,
]
/* flag to avoid accidentally running in prod */
cleanDisabled = flywayCleanDisabled
}
tasks.flywayMigrate.doFirst {
assert apiSvcPgPassword : "must set the apiSvcPgPassword"
assert apiSvcRolePassword : "must set the apiSvcRolePassword"
project.logger.lifecycle "flyway.locations:" + flyway.locations
}
tasks.flywayInfo.doFirst {
assert apiSvcPgPassword : "must set the apiSvcPgPassword"
assert apiSvcRolePassword : "must set the apiSvcRolePassword"
project.logger.lifecycle "flyway.locations:" + flyway.locations
}
// flyway wasn't copying stuff to build/resources
tasks.withType(AbstractFlywayTask) {
dependsOn processResources
}
/* github build failed because the migrations tried to create the app_user,
but that migration task hadn't run yet. */
//tasks.flywayMigrate.mustRunAfter(
// raidV1Project.tasks.flywayMigrate
//)
task cleanJooqGeneratedSrc(type: Delete){
group = "jooq"
delete jooqGeneratedSrcDir
}
jooq{
version = '3.18.0'
configurations {
main { // name of the jOOQ configuration
generateSchemaSourceOnCompilation = false
generationTool {
jdbc {
driver = 'org.postgresql.Driver'
url = apiSvcPgUrl
user = apiSvcPgUser
password = apiSvcPgPassword
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
schemata {
schema {
inputSchema = apiSvcPgSchema
}
}
}
generate {
deprecated = false
records = true
immutablePojos = false
fluentSetters = true
globalTableReferences = false
}
target {
// gets blown away by the clean task each it's run
directory = jooqGeneratedSrcDir
packageName = jooqGeneratedPkg
}
}
}
}
}
}
tasks.generateJooq.dependsOn cleanJooqGeneratedSrc