Latest chatwoot update is breaking the app for me.
-
Hit the exact same issue yesterday — same migration, same error. Root cause: the 1.54.0 migration
AddInboxScopeToEmailTemplatestries to drop the indexindex_email_templates_on_name_and_account_id, but on instances installed at certain older Chatwoot versions that index never existed. Postgres throwsPG::UndefinedObject, and sincedb:migrateruns on every boot, the app is stuck in a restart loop. (Upstream bug — the migration should useif_exists: true.)Fix without rolling back (no data is touched — you just create the index so the migration can drop it):
1. Stop the crash loop:
cloudron debug --app <chatwoot-app-id>2. Safety check — make sure there are no duplicate email templates (the migration later adds unique indices that would fail on duplicates):
cloudron exec --app <app-id> -- bash -c \ 'psql "$CLOUDRON_POSTGRESQL_URL" -c "SELECT name, template_type, locale, account_id, COUNT(*) FROM email_templates GROUP BY 1,2,3,4 HAVING COUNT(*)>1;"'Expected:
(0 rows). If you get rows, dedupe first.3. Create the missing index:
cloudron exec --app <app-id> -- bash -c \ 'psql "$CLOUDRON_POSTGRESQL_URL" -c "CREATE UNIQUE INDEX index_email_templates_on_name_and_account_id ON email_templates (name, account_id);"'4. Run the migration manually (in debug mode the start script hasn't populated the Rails env, so map the Cloudron addon vars):
cloudron exec --app <app-id> -- bash -c ' export POSTGRES_DATABASE="$CLOUDRON_POSTGRESQL_DATABASE" \ POSTGRES_USERNAME="$CLOUDRON_POSTGRESQL_USERNAME" \ POSTGRES_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}" \ POSTGRES_HOST="$CLOUDRON_POSTGRESQL_HOST" \ POSTGRES_PORT="$CLOUDRON_POSTGRESQL_PORT" \ REDIS_URL="redis://$CLOUDRON_REDIS_HOST:$CLOUDRON_REDIS_PORT" \ REDIS_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}" \ RAILS_ENV=production source /app/data/env.sh cd /app/code && bin/rails db:migrate'Watch for
AddInboxScopeToEmailTemplates: migrated— the remaining pending migrations run right after.5. Leave debug mode:
cloudron debug --app <app-id> --disableApp should be back within ~30s. Rolling back to 1.53.1 only postpones this — it'll hit again on the next update until the package/upstream guards the
remove_indexwithif_exists: true. -
Thanks @andreasdueren this worked!
Needed a minute to figure the CLI part out as I hadn't used that before (it's on your machine not on the server or the app container for everybody else)
Also make sure to fill in the password env var names in step 4.

-
@andreasdueren so, is this an upstream bug?
-
Thanks @andreasdueren this worked!
Needed a minute to figure the CLI part out as I hadn't used that before (it's on your machine not on the server or the app container for everybody else)
Also make sure to fill in the password env var names in step 4.

-
@joseph not sure, seems to only affect installations of a certain age. I guess upstream or Cloudron could do what I did manually. But unless more people will reach out this is an isolated issue.
@andreasdueren @joseph overall the upstream project does not seem to be very good with database topics. I recently wanted to create some workflows in my older installation and first needed to fix some indexes as well before the app responded successfully.
My installation ran into this upgrade issue as well, thanks for the commands. Instead of running the last database migrations myself I just disabled the recovery mode and restarted the app.
-
I have a 2 year old installation with the same issue. I'm not sure how to do the CLI thing. Initially, I tried the code in terminal and in putty
totally missing Kinzi's note at first. I'll just revert and wait for a proper package.@humpty Here this should work:
- create backup of chatwoot in case something goes bad
- put app into recovery mode
- enter web terminal and enter
set -euo pipefail source /app/data/env.sh export FRONTEND_URL="${CLOUDRON_APP_ORIGIN}" export REDIS_URL="redis://${CLOUDRON_REDIS_HOST}:${CLOUDRON_REDIS_PORT}" export REDIS_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}" export POSTGRES_DATABASE="${CLOUDRON_POSTGRESQL_DATABASE}" export POSTGRES_USERNAME="${CLOUDRON_POSTGRESQL_USERNAME}" export POSTGRES_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}" export POSTGRES_HOST="${CLOUDRON_POSTGRESQL_HOST}" export POSTGRES_PORT="${CLOUDRON_POSTGRESQL_PORT}" export RAILS_ENV=production echo "Checking for duplicate email templates..." psql "$CLOUDRON_POSTGRESQL_URL" -v ON_ERROR_STOP=1 -c " SELECT name, template_type, locale, account_id, inbox_id, COUNT(*) FROM email_templates GROUP BY name, template_type, locale, account_id, inbox_id HAVING COUNT(*) > 1; " echo "Creating missing legacy index if needed..." psql "$CLOUDRON_POSTGRESQL_URL" -v ON_ERROR_STOP=1 -c " CREATE UNIQUE INDEX IF NOT EXISTS index_email_templates_on_name_and_account_id ON email_templates (name, account_id); " echo "Running Chatwoot database migrations..." cd /app/code bundle exec rails db:migrate echo "Done. Now disable Recovery Mode / Debug Mode and restart the app."- when prompted, take app out of recovery mode
-
My attempts didn't work as the app didn't want to start.
1- Should the app be updated to the broken 1.54 or stick with the working 1.53.1?
2- Should I paste the entire code above in one-shot? If not, then my other attempt by pasting one line at a time didn't work either? I'll try pasting in sections as they're pasted above.Fixed.
To answer my own questions.
1- Yes, apply the code to broken package 1.54.
2- Apply code one section at a time.App package 1.54.0 now starts as it should. Thank you @andreasdueren
-
My attempts didn't work as the app didn't want to start.
1- Should the app be updated to the broken 1.54 or stick with the working 1.53.1?
2- Should I paste the entire code above in one-shot? If not, then my other attempt by pasting one line at a time didn't work either? I'll try pasting in sections as they're pasted above.Fixed.
To answer my own questions.
1- Yes, apply the code to broken package 1.54.
2- Apply code one section at a time.App package 1.54.0 now starts as it should. Thank you @andreasdueren
-
@humpty You need to update it first, then follow those steps. In theory the entire code copied and pasted into the terminal should work, but you can also paste them line by line. Unfortunately I can't test this.
@andreasdueren one line at a time didn't work nor pasting it whole. I pasted them one section at a time and that worked. The "export" lines were done one at a time though. But the "echo" ones had to be as one. e.g.
echo "Checking for duplicate email templates..." psql "$CLOUDRON_POSTGRESQL_URL" -v ON_ERROR_STOP=1 -c " SELECT name, template_type, locale, account_id, inbox_id, COUNT(*) FROM email_templates GROUP BY name, template_type, locale, account_id, inbox_id HAVING COUNT(*) > 1; "This was pasted in one go.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login