Fix migrations

This commit is contained in:
TheSpad 2022-08-27 20:35:37 +01:00
parent 34eee09951
commit 9b753d0667
No known key found for this signature in database
GPG key ID: 08F06191F4587860

View file

@ -5,25 +5,25 @@ MIGRATIONS_HISTORY="/config/.migrations"
echo "[migrations] started"
if [ ! -d $MIGRATIONS_DIR ]; then
if [[ ! -d ${MIGRATIONS_DIR} ]]; then
echo "[migrations] no migrations found"
exit 0
exit
fi
for MIGRATION in $(ls -1 ${MIGRATIONS_DIR}/* | sort -n); do
for MIGRATION in $(find ${MIGRATIONS_DIR}/* | sort -n); do
NAME="$(basename "${MIGRATION}")"
if [ -f $MIGRATIONS_HISTORY ] && grep -Fxq "$NAME" $MIGRATIONS_HISTORY; then
if [[ -f ${MIGRATIONS_HISTORY} ]] && grep -Fxq "${NAME}" ${MIGRATIONS_HISTORY}; then
echo "[migrations] ${NAME}: skipped"
continue
fi
echo "[migrations] ${NAME}: executing..."
chmod +x $MIGRATION
EXIT_CODE=$(/bin/bash ${MIGRATION}; echo $?)
if [ $EXIT_CODE -ne 0 ]; then
echo "[migrations] ${NAME}: failed with exit code $EXIT_CODE, contact support"
exit $EXIT_CODE
chmod +x "${MIGRATION}"
EXIT_CODE=$(/bin/bash "${MIGRATION}"; echo $?)
if [[ ${EXIT_CODE} -ne 0 ]]; then
echo "[migrations] ${NAME}: failed with exit code ${EXIT_CODE}, contact support"
exit "${EXIT_CODE}"
fi
echo $NAME >> $MIGRATIONS_HISTORY
echo "${NAME}" >> ${MIGRATIONS_HISTORY}
echo "[migrations] ${NAME}: succeeded"
done