Fix migrations
rodzic
9a4a2ba8dc
commit
787a600241
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/with-contenv bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
MIGRATIONS_DIR="/migrations"
|
MIGRATIONS_DIR="/migrations"
|
||||||
MIGRATIONS_HISTORY="/config/.migrations"
|
MIGRATIONS_HISTORY="/config/.migrations"
|
||||||
|
@ -6,25 +7,27 @@ MIGRATIONS_HISTORY="/config/.migrations"
|
||||||
echo "[migrations] started"
|
echo "[migrations] started"
|
||||||
|
|
||||||
if [[ ! -d ${MIGRATIONS_DIR} ]]; then
|
if [[ ! -d ${MIGRATIONS_DIR} ]]; then
|
||||||
echo "[migrations] no migrations found"
|
echo "[migrations] no migrations found"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for MIGRATION in $(find ${MIGRATIONS_DIR}/* | sort -n); do
|
for MIGRATION in $(find ${MIGRATIONS_DIR}/* | sort -n); do
|
||||||
NAME="$(basename "${MIGRATION}")"
|
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"
|
echo "[migrations] ${NAME}: skipped"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
echo "[migrations] ${NAME}: executing..."
|
echo "[migrations] ${NAME}: executing..."
|
||||||
chmod +x "${MIGRATION}"
|
chmod +x "${MIGRATION}"
|
||||||
EXIT_CODE=$(/bin/bash "${MIGRATION}"; echo $?)
|
# Execute migration script in a subshell to prevent it from modifying the current environment
|
||||||
if [[ ${EXIT_CODE} -ne 0 ]]; then
|
("${MIGRATION}")
|
||||||
echo "[migrations] ${NAME}: failed with exit code ${EXIT_CODE}, contact support"
|
EXIT_CODE=$?
|
||||||
exit "${EXIT_CODE}"
|
if [[ ${EXIT_CODE} -ne 0 ]]; then
|
||||||
fi
|
echo "[migrations] ${NAME}: failed with exit code ${EXIT_CODE}, contact support"
|
||||||
echo "${NAME}" >> ${MIGRATIONS_HISTORY}
|
exit "${EXIT_CODE}"
|
||||||
echo "[migrations] ${NAME}: succeeded"
|
fi
|
||||||
|
echo "${NAME}" >>${MIGRATIONS_HISTORY}
|
||||||
|
echo "[migrations] ${NAME}: succeeded"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "[migrations] done"
|
echo "[migrations] done"
|
||||||
|
|
Ładowanie…
Reference in New Issue