diff options
author | Petteri Räty <betelgeuse@gentoo.org> | 2011-03-12 21:37:15 +0200 |
---|---|---|
committer | Petteri Räty <betelgeuse@gentoo.org> | 2011-03-12 21:37:15 +0200 |
commit | cf37d090d536d6d5a685aa75f589a3e3dc816472 (patch) | |
tree | de8ac466e139422146c4634fa2e96ec51755584e | |
parent | Questions can belong to many categories (diff) | |
download | recruiting-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.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 |