-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
65 lines (53 loc) · 1.94 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
import groovy.sql.Sql
fileTree('db').each {
apply from: "$it"
}
repositories {
flatDir { dirs 'lib' }
}
configurations {
driver
}
dependencies {
driver fileTree('lib')
}
configurations.driver.each {
GroovyObject.class.classLoader.addURL it.toURL()
}
task loadDriver << {
Class.forName project."${db}Class"
}
task createAccounts(dependsOn: loadDriver) << {
execute(project."${db}JdbcUrl"(dburl, port)) { sql, users, passwords, schemas ->
for (i in 0..(schemas.size() - 1)) {
sql.execute project."${db}CreateSchema"(schemas[i])
println "Schema ${schemas[i]} has been created on | $db | ${dburl}:$port."
sql.execute project."${db}CreateUser"(users[i], passwords[i])
sql.execute project."${db}ConnectUserToSchema"(users[i], passwords[i], schemas[i])
println "User ${users[i]} with password ${passwords[i]} has been created on | $db | ${dburl}:$port."
}
}
}
createAccounts.description = 'Creates DB accounts and schemas. Use comma-separated values in -Pusers= -Ppasswords= -Pschemas='
task cleanup(dependsOn: loadDriver) << {
execute(project."${db}JdbcUrl"(dburl, port)) { sql, users, passwords, schemas ->
for (i in 0..(schemas.size() - 1)) {
sql.execute project."${db}DeleteUser"(users[i])
println "User ${users[i]} has been removed on | $db | ${dburl}:$port."
sql.execute project."${db}DeleteSchema"(schemas[i])
println "Schema ${schemas[i]} has been removed on | $db | ${dburl}:$port."
}
}
}
cleanup.description = 'Removes DB accounts and schemas. Use comma-separated values in -Pusers= -Ppasswords= -Pschemas='
ext.execute = { jdbcUrl, closure ->
def (users, passwords, schemas) = [users, pass, schemas].collect {
it.split(',')
}
if ((users.size() == passwords.size()) && (users.size() == schemas.size())) {
def sql = Sql.newInstance(jdbcUrl, admin, adminpass)
closure(sql, users, passwords, schemas)
} else {
throw new GradleException('You have to pass the same count of users, passwords and schemas.')
}
}