Thursday, July 28, 2016

PostgreSQL migrations' problem solved

I'm not a great PostgreSQL user. Sincerely, I prefer MySQL nine in ten times. But this is not a matter of quality, but just the fact that I started my life as a web developer with the couple PHP/MySQL and use this database for years. I even took a MySQL certification! Then you may see the personal feelings involved in my personal choice.

But life is not what we want, but what we have. And learning to avoid personal feelings is important, specially when you are working with a team.

And this is exactly what happened to me this week, when I started with a new project named Routely, a tool designed to make a revolution in the area of field services (like House Cleaning, Pool cleaning, Pest control, Lawn Service and Parking Lot Service). It helps companies to keep a high quality level for their services; helps contractors to be safe in execution time and helps people that need these services to receive the best for their money.

Routely is a great tool and it will be available soon. And I'm working with a great team, led by a brother of mine, Alex (

The project uses PostgreSQL and I had to install it in my home server to perform the development and test tasks. That's when problems started.

I use PostgreSQL frequently, because I've been using Heroku a lot in the last few years. But then, Heroku infrastructure does all the hard work. A PostgreSQL Heroku user just have to avoid interference and everything will work fine. 

As you may see, I specify databases for sqlite3 for test and development in this configuration file, but when it comes to pg configuration I just let Heroku work and do nothing!

The main point is: I'm not used to install PostgreSQL! My fault! 

Then it wasn't a bit strange when, after install it in my Debian 8, I couldn't run my migrations, getting the following error:

This error

-- enable_extension("citext")
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedFile: ERROR: couldn't open the extension controller file "/usr/share/postgresql/9.4/extension/citext.control": File or directory not found

means I was lacking an extension.

If you face this problem with Debian, there is a simple solution. Run

sudo apt-get install postgresql-contrib libdbd-pg-perl

and have this postgresql-contrib installed. This package has all extensions needed to a smooth run of all your features.

If you are not a Debian user, don't worry. Fedora installs this package as a dependency when you install PostgreSQL, and other distributions probably has a similar package. Google it and you'll surely find. And don't forget other great resources for programmers like StackOverflow.