Skip to content

Instantly share code, notes, and snippets.

@Nimster
Created August 6, 2011 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nimster/1129113 to your computer and use it in GitHub Desktop.
Save Nimster/1129113 to your computer and use it in GitHub Desktop.
Rails lookup v5 - Migrations to create lookup tables
class CreateCarTypeLookupForCar < ActiveRecord::Migration
def self.up
create_table :car_types do |t|
t.string :name
t.timestamps #Btw you can remove these, I don't much like them in type tables anyway
end
remove_column :cars, :type #Let's assume you have one of those now…
add_column :cars, :type, :integer #Maybe put not_null constraints here.
end
def self.down
drop_table :car_types
remove_column :cars, :type
add_column :cars, :type, :string
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment