1

Possible Duplicate:
Database Specific Migration Code

So I run MySQL locally since it's what I have installed and it makes sense to me.

But Heroku uses Postgre and it doesn't have the same field types.

I.e. I use longblob locally and it becomes bytea in my production environment. I use tinytext locally which becomes just text

How do I specify different environments inside of my migrations so I don't have to edit my migrations just for pushing to heroku? (I would like to keep them syntactically correct for my local machine)

Any other suggestions?

Community
  • 1
  • 1
Ken W
  • 962
  • 4
  • 12
  • 19
  • 1
    if you are deploying your app to heroku (and therefor using postgres) - use postgres locally as well - https://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development – house9 Aug 29 '12 at 00:56
  • @house9 is right, don't do this to yourself. There are a lot more differences between MySQL and PostgreSQL than a couple of data types. Database portability is largely a myth unless you're prepared to write your own portability layer (no, ActiveRecord isn't that layer). – mu is too short Aug 29 '12 at 01:42

2 Answers2

2

I understand wanting to run what you're used to locally, as it's easier. Plus, IMO, setting up Postgres locally has always been a pain in the past. However, it really is important to run your development on the same DB as your production server. If you're a Mac user there's a good solution now, brought to you by none other than the Heroku postgres team:

http://postgresapp.com/

Use that and you don't have to worry about this. Otherwise, follow the answer posted by Mu, which will let you do the evil two database thing :)

Community
  • 1
  • 1
Andrew
  • 42,517
  • 51
  • 181
  • 281
0

I'm just guessing here but why don't you create two different migration files, one for development and another for production and use something like this:

rake db:migrate VERSION=00000000000001 RAILS_ENV=production

rake db:migrate VERSION=00000000000002 RAILS_ENV=development
M.Octavio
  • 1,780
  • 2
  • 25
  • 39
  • I guess that could work, I figure there's so much magic in rails already I was hoping for a cleaner method. – Ken W Aug 29 '12 at 00:08
  • maybe there is... thats why I say that I'm just guessing, have you tryed something like the gemfile does? using group :development do (...) just another guessing trying to help :) – M.Octavio Aug 29 '12 at 00:10