Oh no I executed the query on production again!!?

As developers we all have to deal with databases. And when we do it’s never just one database, right? There is one for production, one for acceptance, probably one for some dev or test environment…

…before you know it your database connections window in IntelliJ will look something like the image below. With a non-zero chance of you executing a query on the wrong database.


Whether it’s to test your newly developed query, or to clean up some old unused tables that only exist in dev; sooner or later you have to connect to your databases and execute some query on it.

Now, say you want to drop a customer table from your local database and you accidentally opened the production database console, similar to the image above. Mistakes will be made.

How to avoid disaster?

By far the best way not to have a wrong query executed on the database, is obviously to have no connection to the database. Another decent way is to color code your databases. I recommend having your live databases colored as shown:

Color settings in Intellij

As you can see here I’ve colored the Acceptance and Production database ‘Orange’ and ‘Rose’. This way it becomes (painfully) obvious that I’ve got the production console open with the ‘drop table customers;’-query. Obviously something you really do not want to do in production.

So, to activate these lovely color overlays simply right-click the database in the list on the right, and go to Color Settings:


Pick any color you want and tell IntelliJ where you like to see this color. For readability you might want to disable the ‘In console editors and grids’. That way only the header is colored.


Much more gentle on the eyes!

Obviously this isn’t a monkeyproof solution, but it might just help that one coworker of yours who deleted the production database more than once. While it helps to keep your streak going of never messing up in the first place.

Leave a Reply

Your email address will not be published. Required fields are marked *