Quick productivity hack: `bench-fix`

Who doesn’t you know this situation: you checked out a feature branch, installed a custom app or changed some code, but the system doesn’t behave as expected? This can have a variety of causes:

  • You’re missing some dependencies
  • JavaScript has not been compiled, so you’re running old code
  • Data and code is still in the cache, so you’re running old code and seeing old data
  • Bench has not been restarted, so you’re running old code

The usual solution is to run a variety of bench commands: bench setup requirements, bench migrate, bench build, bench restart, bench clear-cache.

That’s a lot to remember. So why not make life easier and combine them all into one command. Introducing: bench-fix.

Just add the following line to your ~/.bashrc or ~/.zshrc:

alias bench-fix='bench setup requirements && bench migrate && bench build --force && bench clear-cache && bench restart'

Caveats: bench migrate can work on a specific site or an all sites, so you have to think about this when you’re working on a multi-tenant setup.

There you have it. Now you can just run bench-fix and the problems described above will magically disappear. You’ll have to restart your terminal for the command to work.

Extra-tip: this is just server-side. Be sure to hard refresh your browser as well.

16 Likes

Thank you :slight_smile:

I think “yes”, but I there a “Updating” popup on user’s browser during this command ?

&& clear in the end if you want a clean terminal after bench-fix

What’s the difference with bench update ?
What bench update do more than all this ?

You’re right, bench update is pretty similar. Differences are:

  • it runs git pull on all apps (update)

    This might not be what you want. For example, if you’re just working on a custom app.

  • it creates backups first (could be disabled with the --no-backup flag)

    Slows things down, not needed in development.

Not sure if bench update also clears the cache, or if that’s included in bench restart.

bench update --requirements --build --patch --no-backup would be roughly equivalent to bench-fix.

3 Likes

This is meant for development sites only! For production sites, please use bench update.