From 3aba6affd40db84d64d513c977a5767fd867d51a Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Tue, 24 Mar 2026 17:43:12 -0300 Subject: [PATCH] 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) --- docker-compose.coolify.yaml | 10 +++++++--- docker/entrypoints/rails.sh | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docker-compose.coolify.yaml b/docker-compose.coolify.yaml index ba1cbb752..6b4445dee 100644 --- a/docker-compose.coolify.yaml +++ b/docker-compose.coolify.yaml @@ -46,7 +46,7 @@ services: - command: - sh - '-c' - - 'bundle exec rails db:chatwoot_prepare && bundle exec rails branding:update && if [ -n "$${BRAND_ASSETS_URL}" ]; then deployment/extract_brand_assets.sh "$${BRAND_ASSETS_URL}"; fi' + - 'bundle exec rails branding:update && if [ -n "$${BRAND_ASSETS_URL}" ]; then deployment/extract_brand_assets.sh "$${BRAND_ASSETS_URL}"; fi' healthcheck: test: - CMD-SHELL @@ -61,8 +61,12 @@ services: volumes: - 'storage:/app/storage' depends_on: - - postgres - - redis + rails: + condition: service_healthy + postgres: + condition: service_started + redis: + condition: service_started environment: - NODE_ENV=production - RAILS_ENV=production diff --git a/docker/entrypoints/rails.sh b/docker/entrypoints/rails.sh index 77657f6ee..bd17c7f25 100755 --- a/docker/entrypoints/rails.sh +++ b/docker/entrypoints/rails.sh @@ -30,5 +30,11 @@ 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 "$@"