Created
August 6, 2011 07:04
-
-
Save Nimster/1129113 to your computer and use it in GitHub Desktop.
Rails lookup v5 - Migrations to create lookup tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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