2023-03-01 17:32:51 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
rm -f /var/lock/laravel_migration_underway \
|
2024-02-07 15:21:14 +00:00
|
|
|
/var/lock/laravel_migration_complete
|
2023-03-01 17:32:51 +00:00
|
|
|
|
2024-02-07 15:21:14 +00:00
|
|
|
if [[ ${MIGRATE_ENABLE,,} == "on" ]]; then
|
2023-03-01 17:32:51 +00:00
|
|
|
|
2024-02-07 15:21:14 +00:00
|
|
|
# Give a moment for services to wake up
|
|
|
|
echo "[MIGRATION] Waiting until Laravel Ready."
|
|
|
|
sleep 3
|
|
|
|
until [[ -f /var/lock/laravel_ready ]]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo "[MIGRATION] Laravel is ready, running migrations..."
|
2023-03-02 15:59:52 +00:00
|
|
|
|
2024-02-07 15:21:14 +00:00
|
|
|
cd /app || exit
|
2023-03-02 15:59:52 +00:00
|
|
|
|
2024-02-07 15:21:14 +00:00
|
|
|
# Run migration
|
|
|
|
touch /var/lock/laravel_migration_underway
|
2023-03-01 17:32:51 +00:00
|
|
|
|
2024-02-07 15:21:14 +00:00
|
|
|
if [[ ${MIGRATE_CLEAN,,} == "on" ]]; then
|
|
|
|
php /app/artisan migrate:fresh --force
|
|
|
|
php /app/artisan migrate --force # First run will fail due to permissions. We can ignore, but need to migrate again to finish.
|
|
|
|
else
|
|
|
|
# If we run this on first commit, it is the same as migrate:fresh, first run may fail and we need to try one more time.
|
|
|
|
php /app/artisan migrate --force || php /app/artisan migrate --force
|
|
|
|
fi
|
2023-03-02 15:59:52 +00:00
|
|
|
|
2024-02-07 15:21:14 +00:00
|
|
|
if [[ ${SEEDERS,,} == "on" ]]; then
|
|
|
|
php /app/artisan db:seed -q
|
|
|
|
fi
|
2023-03-02 15:59:52 +00:00
|
|
|
|
2024-02-07 15:21:14 +00:00
|
|
|
rm /var/lock/laravel_migration_underway
|
|
|
|
touch /var/lock/laravel_migration_complete
|
|
|
|
echo "[MIGRATION] Migration complete!"
|
2023-03-02 15:59:52 +00:00
|
|
|
|
|
|
|
else
|
2024-02-07 15:21:14 +00:00
|
|
|
echo "[MIGRATION] Not enabled. Set MIGRATE_ENABLE = on to enable."
|
2023-03-02 15:59:52 +00:00
|
|
|
fi
|
2023-03-01 17:32:51 +00:00
|
|
|
|
|
|
|
# Sleep forever (and sleep again in case the sleep process is killed)
|
|
|
|
while true; do
|
2024-02-07 15:21:14 +00:00
|
|
|
sleep infinity
|
|
|
|
done
|