forked from miso-lims/miso-lims
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact-migrations
executable file
·54 lines (48 loc) · 1.54 KB
/
compact-migrations
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
#!/bin/sh
# Compact all 8xxx migrations into a single migration as part of the release process.
set -eu
cd "$(dirname $0)/sqlstore/src/main/resources/db/migration"
# Determine the last migration in the working directory
LAST="$(basename "$(ls V[0-5][0-9][0-9][0-9]_*.sql | sort | tail -n 1)")"
echo "Previous migration is ${LAST}."
LAST_ID="$(echo "${LAST}" | cut -c 2-5 | sed -e 's/^0*//')"
# Determine if we are on the mainline branch or a site-specific branch.
BRANCH="$(git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)")"
if [ "${BRANCH#*/}" = "develop" ] && git remote show -n "${BRANCH%/*}" | grep "TGAC/miso-lims.git" > /dev/null
then
echo "This is mainline"
TAIL="main"
ID=$(((${LAST_ID} / 10 + 1) * 10))
START_BANNER=""
END_BANNER=""
else
echo "This is site-specific."
TAIL="site"
ID=$((${LAST_ID} + 1))
if [ $((${ID} % 10)) -eq 0 ]
then
echo "Too many site-specific releases since last mainline release."
exit 1
fi
START_BANNER="--StartNoTest"
END_BANNER="--EndNoTest"
fi
NEXT="V$(printf "%04d" ${ID})__auto_${TAIL}.sql"
echo "Next migration will be ${NEXT}."
# Concatenate all the 8xxx files and remove them from git
rm -f "${NEXT}"
for FILE in $(find . -name "V8[0-9][0-9][0-9]_*.sql" | sort)
do
NAME=$(basename "${FILE}" .sql)
echo -- ${NAME#V*__} >> "${NEXT}"
echo ${START_BANNER} >> "${NEXT}"
# This sed command forces a newline at the end of the file
sed -e '$a\' "${FILE}" >> "${NEXT}"
echo ${END_BANNER} >> "${NEXT}"
echo >> "${NEXT}"
git rm "${FILE}"
done
if [ -f "${NEXT}" ]
then
git add "${NEXT}"
fi