Archive for the ‘Heroku’ Category

Migrating from MySQL to PostgreSQL In RoR Application

Since the day Heroku has made Postgres as the default database, the popularity of Postgres has gone through the roof. A lot of developers however feel that its quite a task to move from mysql to Postgres, so we thought of putting up a small writeup on how one can go about migrating from mysql from Postgres. PostgreSQL
  • Often simply Postgres, is an object-relational database management system (ORDBMS) available for many platforms including Linux, FreeBSD, Solaris, MS Windows and Mac OS X.
  • It implements the majority of the SQL:2008 standard, is ACID-compliant, is fully transactional (including all DDL statements), has extensible data types, operators, and indexes, and has a large number of extensions written by third parties
Migrating from MySQL to PostgreSQL – Why ?
  • One of the reasons is definitely for engineers developing on Heroku platform since postgres is now the default database on Heroku.
  • MySQL is faster and easier to use than PostgreSQL but PostgreSQL is perceived as more powerful, more focused on data integrity, and stricter at complying with SQL specifications.
Installing Postgres: For the purpose of blog, we will assume that the operating system is ubuntu, it should be equally easier to install it on other operating systems. Open the terminal and type following command to install postgresql :-
sudo apt-get install postgresql postgresql-client /*For Ubuntu Operating System*/
Now your postgresql server and client is installed. You can verify the installation by logging into the postgresql console by using this command:-
sudo -u postgres psql
NOTE:- use ‘\q’ to exit from the postgresql console. Creating the user This step is something different from mysql and developers migrating from mysql found this to be quite difficult to understand. We will try to decipher it here. Postgresql creates default superuser called “postgres” but we can’t use it in our application because of postgres security reasons . So, we need to create a new user that our application can use to login to postgres. To do so, go to terminal and type the following command to create a new user :-
sudo -u postgres createuser
Pressing ENTER after writing this command will ask you some questions like name of user and basic privileges to be given. Simply type the name of the user and answer of other questions in y/n like:- Enter name of role to add: user_name /*name of the user to be created*/ Shall the new role be a superuser? (y/n) /*Type y to make the user Superuser, otherwise type n*/ You are done creating the user, we will now create the database and assign the privileges for this database to the given user. This is almost similar like we do in mysql. Read More

Bundle: Command Not Found: Heroku

Recently, I had an application where we had to use ruby 1.8.7 instead of default ruby on heroku cedar stack(1.9.x) so what we did was following:
  • Create a Heroku instance and deployed our application on the instance.
  • After deploying we changed the ruby version to 1.8.7 in Gemfile and deployed the application back.
  • Results: A dreaded “Bundle: Command not found” error.
We tried installing bundler and many other things but the error wont go away. We requested for a heroku support at that time and they explained that when you change ruby version after the deployment, heroku yet does not changes the gem path so we have to manually set the config using following commands:
heroku config:add GEM_PATH=vendor/bundle/1.8
We tried the solution and this worked for us. The Heroku team however explained that in case you use a custom ruby in a stack then we need to spin up an instance and then add the ruby directive at the time of deploying the application otherwise the gem path would not be configured. I hope this saves time for someone !!