Mysql column type set


#1

Is it possible to use Mysql column type SET within RoR migration files?


#2

I am not familiar with “SET” but you can pass any sql in a migration
with the “Execute” command
Like so: (this is adding a foreign key and a GUID id rather than an
auto-increment integer, but you get the point.)

class CreateSeats < ActiveRecord::Migration
def self.up

create_table(:seats,  :id => false) do |t|
  t.string :id, :limit => 32, :null => false
  t.string :venue_id, :limit => 32, :null => false
  t.string :name
  t.string :section
  t.string :seat_row
  t.string :seat_number
  t.string :seat_type

  t.timestamps
end
execute "ALTER TABLE `seats` ADD PRIMARY KEY (`id`)"

#add a foreign key
execute "ALTER TABLE seats ADD CONSTRAINT fk_seats_venues FOREIGN

KEY (venue_id) REFERENCES venues(id)"

end

def self.down
#Drop foreign key
execute “ALTER TABLE seats DROP FOREIGN KEY fk_seats_venues”
drop_table :seats
end
end


#3

Thank you Teedub Ill pass it as an sql statement guess that’s the
easiest
way :slight_smile: