entrypoint: optional RUN_FRESH_MIGRATE for one-shot DB reset
This commit is contained in:
@@ -7,14 +7,18 @@ cd /app
|
||||
mkdir -p storage/framework/{cache,sessions,views,testing} storage/logs storage/app/public bootstrap/cache
|
||||
chown -R www-data:www-data storage bootstrap/cache 2>/dev/null || true
|
||||
|
||||
# Run migrations on first boot (idempotent)
|
||||
if [ "${RUN_MIGRATIONS:-true}" = "true" ]; then
|
||||
# DESTRUCTIVE: drops all tables + re-runs migrations + seed.
|
||||
# Set in Coolify only when intentionally resetting DB. Remove after.
|
||||
if [ "${RUN_FRESH_MIGRATE:-false}" = "true" ]; then
|
||||
echo "[entrypoint] !!! RUN_FRESH_MIGRATE=true — dropping all tables !!!"
|
||||
php artisan migrate:fresh --force --seed --no-interaction || echo "[entrypoint] fresh failed"
|
||||
elif [ "${RUN_MIGRATIONS:-true}" = "true" ]; then
|
||||
echo "[entrypoint] Running migrations..."
|
||||
php artisan migrate --force --no-interaction || echo "[entrypoint] migrate failed (non-fatal)"
|
||||
fi
|
||||
|
||||
# Run seeders if requested. Uses firstOrCreate so it's idempotent.
|
||||
if [ "${RUN_SEED:-false}" = "true" ]; then
|
||||
if [ "${RUN_SEED:-false}" = "true" ] && [ "${RUN_FRESH_MIGRATE:-false}" != "true" ]; then
|
||||
echo "[entrypoint] Running database seed..."
|
||||
php artisan db:seed --force --no-interaction || echo "[entrypoint] seed failed (non-fatal)"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user