I\'m trying to push a brand new Ruby on Rails app to Heroku. Currently, it sits on MySQL. It looks like Heroku doesn\'t really support MySQL and so we are considering using
It should be simplicity itself: port the DDL from MySQL to PostgreSQL.
Does Heroku have any schema creation scripts? I'd depend on those if they were available.
MySQL and PostgreSQL are different (e.g. identity type for MySQL, sequences for PostgreSQL). But the port shouldn't be too hard. How many tables? Tens are doable.
Don't feel you have to migrate to Postgres - there are several MySQL Addon providers available on Heroku - http://addons.heroku.com/cleardb is the one I've had the most success with.
If you have no data to migrate, it should be as simple as telling your Gemfile
to use the pg
gem instead, running bundle install
, and updating your database.yml
file to point to your PostgreSQL databases. Then just run your migrations (rake db:migrate
) and everything should work great.
Common issues:
char(n)
column unless your server is in strict mode, PostgreSQL will complain and make you truncate your string yourself.(1) will be an issue if you use AR's group
method in any of your queries or GROUP BY in any raw SQL. Do some searching for column "X" must appear in the GROUP BY clause or be used in an aggregate function
and you'll see some examples and common solutions.
(2) will be an issue if you use string columns anywhere in your application and your models aren't properly validating the length of all incoming string values. Note that creating a string column in Rails without specifying a limit actually creates a varchar(255)
column so there actually is an implicit :limit => 255
even though you didn't specify one. An alternative is to use t.text
for your strings instead of t.string
; this will let you work with arbitrarily large strings without penalty (for PostgreSQL at least). As Erwin notes below (and every other chance he gets), varchar(n)
is a bit of an anachronism in the PostgreSQL world.
(3) shouldn't be a problem unless you have raw SQL in your code.
(4) will be an issue if you're using LIKE anywhere in your application. You can fix this one by changing a like b
to lower(a) like lower(b)
(or upper(a) like upper(b)
if you like to shout) or a ilike b
but be aware that PostgreSQL's ILIKE is non-standard.
There are other differences that can cause trouble but those seem like the most common issues.
You'll have to review a few things to feel safe:
group
calls.where
calls).