Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps - Status | Demo | Docs | Install
  1. Cloudron Forum
  2. Chatwoot
  3. Latest chatwoot update is breaking the app for me.

Latest chatwoot update is breaking the app for me.

Scheduled Pinned Locked Moved Chatwoot
12 Posts 5 Posters 193 Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • andreasduerenA andreasdueren

    @Kinzi

    Hit the exact same issue yesterday — same migration, same error. Root cause: the 1.54.0 migration AddInboxScopeToEmailTemplates tries to drop the index index_email_templates_on_name_and_account_id, but on instances installed at certain older Chatwoot versions that index never existed. Postgres throws PG::UndefinedObject, and since db:migrate runs on every boot, the app is stuck in a restart loop. (Upstream bug — the migration should use if_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> --disable
    

    App 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_index with if_exists: true.

    J Offline
    J Offline
    joseph
    Staff
    wrote last edited by
    #3

    @andreasdueren so, is this an upstream bug?

    andreasduerenA 1 Reply Last reply
    1
    • KinziK Offline
      KinziK Offline
      Kinzi
      wrote last edited by
      #4

      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. 🙂

      andreasduerenA 1 Reply Last reply
      2
      • J joseph

        @andreasdueren so, is this an upstream bug?

        andreasduerenA Online
        andreasduerenA Online
        andreasdueren
        App Dev
        wrote last edited by
        #5

        @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.

        fbartelsF 1 Reply Last reply
        1
        • KinziK Kinzi

          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. 🙂

          andreasduerenA Online
          andreasduerenA Online
          andreasdueren
          App Dev
          wrote last edited by
          #6

          @Kinzi yes forgot to look up the correct Postgres ENV lol

          1 Reply Last reply
          1
          • andreasduerenA andreasdueren

            @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.

            fbartelsF Offline
            fbartelsF Offline
            fbartels
            App Dev
            wrote last edited by
            #7

            @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.

            1 Reply Last reply
            2
            • humptyH Offline
              humptyH Offline
              humpty
              wrote last edited by
              #8

              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.

              andreasduerenA 1 Reply Last reply
              0
              • humptyH humpty

                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.

                andreasduerenA Online
                andreasduerenA Online
                andreasdueren
                App Dev
                wrote last edited by
                #9

                @humpty Here this should work:

                1. create backup of chatwoot in case something goes bad
                2. put app into recovery mode
                3. 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."
                
                1. when prompted, take app out of recovery mode
                1 Reply Last reply
                2
                • humptyH Offline
                  humptyH Offline
                  humpty
                  wrote last edited by humpty
                  #10

                  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

                  andreasduerenA 1 Reply Last reply
                  2
                  • humptyH humpty

                    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

                    andreasduerenA Online
                    andreasduerenA Online
                    andreasdueren
                    App Dev
                    wrote last edited by
                    #11

                    @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.

                    humptyH 1 Reply Last reply
                    0
                    • andreasduerenA 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.

                      humptyH Offline
                      humptyH Offline
                      humpty
                      wrote last edited by
                      #12

                      @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.

                      1 Reply Last reply
                      2

                      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
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Bookmarks
                      • Search