How do I check the Database type in a Rails Migration?

Posted by Shaun F on Stack Overflow See other posts from Stack Overflow or by Shaun F
Published on 2009-10-27T03:22:35Z Indexed on 2010/03/29 9:03 UTC
Read the original article Hit count: 170

Filed under:
|
|

I have the following migration and I want to be able to check if the current database related to the environment is a mysql database. If it's mysql then I want to execute the SQL that is specific to the database.

How do I go about this?

class AddUsersFb < ActiveRecord::Migration

  def self.up
    add_column :users, :fb_user_id, :integer
    add_column :users, :email_hash, :string
    #if mysql
    #execute("alter table users modify fb_user_id bigint")
  end

  def self.down
    remove_column :users, :fb_user_id
    remove_column :users, :email_hash
  end

end

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about migrations