-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·73 lines (57 loc) · 2.26 KB
/
run.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
main() {
info 'initialize'
export FLYWAY_VERSION="4.0.1"
echo "configuring version $FLYWAY_VERSION of Flyway"
if [ ! -n "$WERCKER_FLYWAY_MIGRATE_HOST" ]; then
fail 'missing or empty option host, please check wercker.yml'
fi
if [ ! -n "$WERCKER_FLYWAY_MIGRATE_USERNAME" ]; then
fail 'missing or empty option username, please check wercker.yml'
fi
if [ ! -n "$WERCKER_FLYWAY_MIGRATE_PASSWORD" ]; then
fail 'missing or empty option password, please check wercker.yml'
fi
if [ ! -n "$WERCKER_FLYWAY_MIGRATE_DATABASE" ]; then
fail 'missing or empty option database, please check wercker.yml'
fi
if [ ! -n "$WERCKER_FLYWAY_MIGRATE_DRIVER" ]; then
fail 'missing or empty option driver, please check wercker.yml'
fi
if [ ! -n "$WERCKER_FLYWAY_MIGRATE_MIGRATION_DIR" ]; then
fail 'missing or empty option migration-dir, please check wercker.yml'
fi
if [ ! -n "$WERCKER_FLYWAY_MIGRATE_MIGRATION_PREFIX" ]; then
WERCKER_FLYWAY_MIGRATE_MIGRATION_PREFIX="V"
fi
info 'updating apt-get'
sudo apt-get update
info 'installing curl'
sudo apt-get install curl -y
info 'downloading flyway'
curl -L https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/4.0.1/flyway-commandline-4.0.1-linux-x64.tar.gz > /tmp/flyway.tar.gz
mkdir /tmp/flyway
tar -zxvf /tmp/flyway.tar.gz -C /tmp/flyway
mkdir "$WERCKER_STEP_ROOT/flyway"
mv "/tmp/flyway/flyway-$FLYWAY_VERSION/"* "$WERCKER_STEP_ROOT/flyway/"
info 'starting flyway migration'
migration_dir="$WERCKER_ROOT/$WERCKER_FLYWAY_MIGRATE_MIGRATION_DIR"
if cd "$migration_dir";
then
debug "changed directory $migration_dir, content is: $(ls -l)"
else
fail "unable to change directory to $migration_dir"
fi
set +e
local MIGRATE="$WERCKER_STEP_ROOT/flyway/flyway migrate -url=jdbc:$WERCKER_FLYWAY_MIGRATE_DRIVER://$WERCKER_FLYWAY_MIGRATE_HOST/$WERCKER_FLYWAY_MIGRATE_DATABASE -user=$WERCKER_FLYWAY_MIGRATE_USERNAME -password=$WERCKER_FLYWAY_MIGRATE_PASSWORD -locations=filesystem:$WERCKER_ROOT/$WERCKER_FLYWAY_MIGRATE_MIGRATION_DIR -sqlMigrationPrefix=$WERCKER_FLYWAY_MIGRATE_MIGRATION_PREFIX"
info 'migrating'
eval "$MIGRATE"
if [ $? -eq 0 ]
then
success 'finished flyway migration';
else
fail 'flyway failed';
fi
set -e
}
main