2024-01-05 23:16:26 +00:00
|
|
|
#!/bin/bash
|
2024-01-15 17:16:00 +00:00
|
|
|
: "${ENTRYPOINT_ROOT:="/docker"}"
|
|
|
|
|
|
|
|
# shellcheck source=SCRIPTDIR/../helpers.sh
|
|
|
|
source "${ENTRYPOINT_ROOT}/helpers.sh"
|
2024-01-05 23:16:26 +00:00
|
|
|
|
|
|
|
entrypoint-set-script-name "$0"
|
|
|
|
|
2024-01-05 23:54:17 +00:00
|
|
|
# Allow automatic applying of outstanding/new migrations on startup
|
2024-01-15 20:42:11 +00:00
|
|
|
: "${DB_APPLY_NEW_MIGRATIONS_AUTOMATICALLY:=0}"
|
2024-01-05 23:54:17 +00:00
|
|
|
|
|
|
|
# Wait for the database to be ready
|
2024-01-05 23:16:26 +00:00
|
|
|
await-database-ready
|
|
|
|
|
2024-01-26 20:45:38 +00:00
|
|
|
# Run the migrate:status command and capture output
|
|
|
|
output=$(run-as-runtime-user php artisan migrate:status || :)
|
|
|
|
|
|
|
|
# By default we have no new migrations
|
2024-01-05 23:54:17 +00:00
|
|
|
declare -i new_migrations=0
|
|
|
|
|
2024-01-26 20:45:38 +00:00
|
|
|
# Detect if any new migrations are available by checking for "No" in the output
|
|
|
|
echo "$output" | grep No && new_migrations=1
|
|
|
|
|
|
|
|
if is-false "${new_migrations}"; then
|
|
|
|
log-info "No new migrations detected"
|
2024-01-05 23:54:17 +00:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-01-26 20:45:38 +00:00
|
|
|
log-warning "New migrations available"
|
|
|
|
|
|
|
|
# Print the output
|
|
|
|
echo "$output"
|
2024-01-05 23:54:17 +00:00
|
|
|
|
2024-01-15 20:42:11 +00:00
|
|
|
if is-false "${DB_APPLY_NEW_MIGRATIONS_AUTOMATICALLY}"; then
|
2024-01-15 14:16:54 +00:00
|
|
|
log-info "Automatic applying of new database migrations is disabled"
|
2024-01-15 20:42:11 +00:00
|
|
|
log-info "Please set [DB_APPLY_NEW_MIGRATIONS_AUTOMATICALLY=1] in your [.env] file to enable this."
|
2024-01-15 14:16:54 +00:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-01-05 23:54:17 +00:00
|
|
|
run-as-runtime-user php artisan migrate --force
|