forked from vmware-archive/pal-tracker-distributed-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate-cf.sh
executable file
·55 lines (44 loc) · 1.41 KB
/
migrate-cf.sh
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
#!/usr/bin/env bash
set -e
cfMigrate() {
trap "kill 0" EXIT
appName=$1
migrationsPath=Databases/${appName/tracker-/}-database
appGuid=$(cf app $1 --guid)
credentials=$(cf curl v2/apps/${appGuid}/env | jq -r .system_env_json'.VCAP_SERVICES["p-mysql"][].credentials')
database=$(echo ${credentials} | jq -r .name)
username=$(echo ${credentials} | jq -r .username)
hostname=$(echo ${credentials} | jq -r .hostname)
password=$(echo ${credentials} | jq -r .password)
openTunnel ${hostname} ${appName}
migrate ${username} ${password} ${database} ${migrationsPath}
closeTunnel $!
wait
}
function openTunnel() {
echo -e "\nOpening tunnel..."
local hostname=$1
local appName=$2
cf ssh -N -L 63306:${hostname}:3306 ${appName} &
sleep 5
}
function closeTunnel() {
echo -e "\nClosing tunnel..."
kill -9 $1
wait $1 2>/dev/null
}
function migrate() {
echo -e "\nRunning migrations...\n"
local username=$1
local password=$2
local database=$3
local migrationsPath=$4
flyway -user=${username} \
-password=${password} \
-url="jdbc:mysql://127.0.0.1:63306/${database}" \
-locations=filesystem:${migrationsPath} migrate
}
cfMigrate tracker-allocations &&
cfMigrate tracker-backlog &&
cfMigrate tracker-registration &&
cfMigrate tracker-timesheets