From fdf875de262eaa95f47713571a0e918ab6be2cad Mon Sep 17 00:00:00 2001 From: Bryan Larsen Date: Mon, 3 Jun 2013 16:38:25 +0200 Subject: [PATCH] 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. --- .../20130109022053_add_story_status_model.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 db/migrate/20130109022053_add_story_status_model.rb diff --git a/db/migrate/20130109022053_add_story_status_model.rb b/db/migrate/20130109022053_add_story_status_model.rb new file mode 100644 index 0000000..4372ea9 --- /dev/null +++ b/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