iachat/docker/entrypoints/rails.sh
gabrieljablonski 3aba6affd4 fix(deploy): run migrations before server boot to prevent stale schema errors
Sidekiq was starting before migrations ran, causing RuntimeError on the
group_type enum. Moved db:chatwoot_prepare from post_start into the rails
entrypoint and made sidekiq depend on the rails healthcheck.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 17:43:12 -03:00

41 lines
1002 B
Bash
Executable File

#!/bin/sh
set -x
# Remove a potentially pre-existing server.pid for Rails.
rm -rf /app/tmp/pids/server.pid
rm -rf /app/tmp/cache/*
echo "Waiting for postgres to become ready...."
# Let DATABASE_URL env take presedence over individual connection params.
# This is done to avoid printing the DATABASE_URL in the logs
$(docker/entrypoints/helpers/pg_database_url.rb)
PG_READY="pg_isready -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USERNAME"
until $PG_READY
do
sleep 2;
done
echo "Database ready to accept connections."
#install missing gems for local dev as we are using base image compiled for production
bundle install
BUNDLE="bundle check"
until $BUNDLE
do
sleep 2;
done
# Run pending migrations before starting the server so that workers
# (sidekiq) that depend on the rails healthcheck never see a stale schema.
echo "Running db:chatwoot_prepare..."
bundle exec rake db:chatwoot_prepare
echo "Database preparation complete."
# Execute the main process of the container
exec "$@"