diff options
-rw-r--r-- | db/migrate/20110312181715_add_question_category_pivot.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/db/migrate/20110312181715_add_question_category_pivot.rb b/db/migrate/20110312181715_add_question_category_pivot.rb index ef1a810..c71032d 100644 --- a/db/migrate/20110312181715_add_question_category_pivot.rb +++ b/db/migrate/20110312181715_add_question_category_pivot.rb @@ -6,6 +6,9 @@ class AddQuestionCategoryPivot < ActiveRecord::Migration end add_index :question_categories, [:question_id, :category_id], :unique => true + execute 'INSERT INTO question_categories (question_id, category_id) + SELECT id, category_id FROM questions WHERE category_id IS NOT NULL' + remove_column :questions, :category_id remove_index :questions, :name => :index_questions_on_category_id rescue ActiveRecord::StatementInvalid |