/
entrypoint.sh
175 lines (152 loc) · 6.85 KB
/
entrypoint.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
set -o pipefail
set -o errtrace
set -o nounset
set -o errexit
LIQUIBASE_OPTS="$LIQUIBASE_OPTS --defaultsFile=/liquibase.properties"
echo -n > /liquibase.properties
## Properties file
if [[ -f liquibase.properties ]]; then
cat liquibase.properties >> /liquibase.properties
fi
## Database driver
if [[ -n "$LIQUIBASE_DRIVER" ]]; then
sed -i '/^driver:/d' /liquibase.properties
echo "driver: ${LIQUIBASE_DRIVER}" >> /liquibase.properties
fi
## Classpath
if [[ -n "$LIQUIBASE_CLASSPATH" ]]; then
echo "classpath: ${LIQUIBASE_CLASSPATH}" >> /liquibase.properties
fi
## Database url
if [[ -n "$LIQUIBASE_URL" ]]; then
echo "url: ${LIQUIBASE_URL}" >> /liquibase.properties
fi
## Database username
if [[ -n "$LIQUIBASE_USERNAME" ]]; then
echo "username: ${LIQUIBASE_USERNAME}" >> /liquibase.properties
fi
## Database password
if [[ -n "$LIQUIBASE_PASSWORD" ]]; then
echo "password: ${LIQUIBASE_PASSWORD}" >> /liquibase.properties
fi
## Database contexts
if [[ -n "$LIQUIBASE_CONTEXTS" ]]; then
echo "contexts: ${LIQUIBASE_CONTEXTS}" >> /liquibase.properties
fi
## Database changelog file
if [[ -n "$LIQUIBASE_CHANGELOG" ]]; then
if ! grep -q '^changeLogFile' /liquibase.properties; then
echo "changeLogFile: ${LIQUIBASE_CHANGELOG}" >> /liquibase.properties
fi
fi
function executeLiquibase() {
exec /opt/liquibase/liquibase $LIQUIBASE_OPTS "$@"
}
if [[ "$#" -ge 1 ]]; then
TASK="$1"
shift
case "$TASK" in
## Custom liquibase command
liquibase)
executeLiquibase "$@"
;;
## Database Update Commands
update|updateCount|updateSQL|updateCountSQL) ;&
## Database Rollback Commands
rollback|rollbackToDate|rollbackCount|rollbackSQL|rollbackToDateSQL|rollbackCountSQL|updateTestingRollback|generateChangeLog) ;&
## Diff Commands
diff|diffChangeLog) ;&
## Documentation Commands
dbDoc) ;&
## Maintenance Commands
status|validate|changelogSync|changelogSyncSQL|markNextChangeSetRan|listLocks|releaseLocks|dropAll|clearCheckSums)
if [[ "$#" -eq 0 ]]; then
executeLiquibase "$TASK"
else
executeLiquibase "$TASK" "$@"
fi
;;
## show configuration
showConf)
cat /liquibase.properties
;;
## Help
help)
cat <<EOF
Database Update Commands
-------------------------------------------------------------------------------
update Updates database to current version.
updateCount <value> Applies the next <value> change sets.
updateSQL Writes SQL to update database to current
version to STDOUT.
updateCountSQL <value> Writes SQL to apply the next <value>
change sets to STDOUT.
Database Rollback Commands
-------------------------------------------------------------------------------
rollback <tag> Rolls back the database to the state it
was in when the tag was applied.
rollbackToDate <date/time> Rolls back the database to the state it
was in at the given date/time.
rollbackCount <value> Rolls back the last <value> change sets.
rollbackSQL <tag> Writes SQL to roll back the database to
the state it was in when the tag was
applied to STDOUT.
rollbackToDateSQL <date/time> Writes SQL to roll back the database to
the state it was in at the given date/time
version to STDOUT.
rollbackCountSQL <value> Writes SQL to roll back the last <value>
change sets to STDOUT.
futureRollbackSQL Writes SQL to roll back the database to
the current state after the changes in
the changeslog have been applied.
updateTestingRollback Updates the database, then rolls back
changes before updating again.
generateChangeLog generateChangeLog of the database to
standard out. v1.8 requires the dataDir
parameter currently.
Diff Commands
-------------------------------------------------------------------------------
diff [diff parameters] Writes description of differences to
standard out.
diffChangeLog [diff parameters] Writes Change Log XML to update the base
database to the target database to
standard out.
Documentation Commands
-------------------------------------------------------------------------------
dbDoc <outputDirectory> Generates Javadoc-like documentation based
on current database and change log.
Maintenance Commands
-------------------------------------------------------------------------------
tag <tag> "Tags" the current database state for
future rollback.
tagExists <tag> Checks whether the given tag is already
existing.
status Outputs count (list if --verbose) of unrun
change sets.
validate Checks the changelog for errors.
changelogSync Mark all changes as executed in the
database.
changelogSyncSQL Writes SQL to mark all changes as executed
in the database to STDOUT.
markNextChangeSetRan Mark the next change set as executed in
the database.
listLocks Lists who currently has locks on the
database changelog.
releaseLocks Releases all locks on the database
changelog.
dropAll Drops all database objects owned by the
user. Note that functions, procedures
and packages are not dropped
(limitation in 1.8.1).
clearCheckSums Removes current checksums from database.
On next run checksums will be recomputed.
EOF
exit 1
;;
## Default task (eg. sh, bash)
*)
exec "$TASK" "$@"
;;
esac
fi