aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Räty <betelgeuse@gentoo.org>2011-03-12 21:37:15 +0200
committerPetteri Räty <betelgeuse@gentoo.org>2011-03-12 21:37:15 +0200
commitcf37d090d536d6d5a685aa75f589a3e3dc816472 (patch)
treede8ac466e139422146c4634fa2e96ec51755584e
parentQuestions can belong to many categories (diff)
downloadrecruiting-webapp-cf37d090d536d6d5a685aa75f589a3e3dc816472.tar.gz
recruiting-webapp-cf37d090d536d6d5a685aa75f589a3e3dc816472.tar.bz2
recruiting-webapp-cf37d090d536d6d5a685aa75f589a3e3dc816472.zip
Preserve existing categories
When migrating to many to many question categories bring over the existing category information.
-rw-r--r--db/migrate/20110312181715_add_question_category_pivot.rb3
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