Permalink
Browse files

story-status-model-migration

Now run the migration generator

    $ hobo generate migration

You'll see that the migration generator considers this change to be ambiguous. Whenever there are columns removed *and* columns added, the migration generator can't tell whether you're actually removing one column and adding another, or if you are renaming the old column. It's also pretty fussy about what it makes you type. We really don't want to play fast and lose with your precious data, so to confirm that you want to drop the 'status' column, you have to type in full: "drop status".

Once you've done that you'll see that the generated migration includes the creation of the new foreign key and the removal of the old status column.  Press `g` now to generate the migration without running it.
  • Loading branch information...
bryanlarsen authored and iox committed Jun 3, 2013
1 parent 28eb34f commit fdf875de262eaa95f47713571a0e918ab6be2cad
Showing with 23 additions and 0 deletions.
  1. +23 −0 db/migrate/20130109022053_add_story_status_model.rb
@@ -0,0 +1,23 @@
class AddStoryStatusModel < ActiveRecord::Migration
def self.up
create_table :story_statuses do |t|
t.string :name
t.datetime :created_at
t.datetime :updated_at
end
add_column :stories, :status_id, :integer
remove_column :stories, :status
add_index :stories, [:status_id]
end
def self.down
remove_column :stories, :status_id
add_column :stories, :status, :string
drop_table :story_statuses
remove_index :stories, :name => :index_stories_on_status_id rescue ActiveRecord::StatementInvalid
end
end

0 comments on commit fdf875d

Please sign in to comment.