Merge pull request #127 from linuxserver/focal-migrations

Fix migrations
pull/129/head
Eric Nemchik 2022-10-30 12:59:18 -05:00 zatwierdzone przez GitHub
commit d29fc56f32
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 20 dodań i 17 usunięć

Wyświetl plik

@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
MIGRATIONS_DIR="/migrations"
MIGRATIONS_HISTORY="/config/.migrations"
@ -6,25 +7,27 @@ MIGRATIONS_HISTORY="/config/.migrations"
echo "[migrations] started"
if [[ ! -d ${MIGRATIONS_DIR} ]]; then
echo "[migrations] no migrations found"
exit
echo "[migrations] no migrations found"
exit
fi
for MIGRATION in $(find ${MIGRATIONS_DIR}/* | sort -n); do
NAME="$(basename "${MIGRATION}")"
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}"
fi
echo "${NAME}" >> ${MIGRATIONS_HISTORY}
echo "[migrations] ${NAME}: succeeded"
NAME="$(basename "${MIGRATION}")"
if [[ -f ${MIGRATIONS_HISTORY} ]] && grep -Fxq "${NAME}" ${MIGRATIONS_HISTORY}; then
echo "[migrations] ${NAME}: skipped"
continue
fi
echo "[migrations] ${NAME}: executing..."
chmod +x "${MIGRATION}"
# Execute migration script in a subshell to prevent it from modifying the current environment
("${MIGRATION}")
EXIT_CODE=$?
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 "[migrations] ${NAME}: succeeded"
done
echo "[migrations] done"