diff options
| author | mo khan <mo@mokhan.ca> | 2014-05-20 21:48:49 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-05-20 21:48:49 -0600 |
| commit | cb20f2700bbb7721148d48a13b8b05130e331be3 (patch) | |
| tree | f79456afeb75d9cf0215f9754f7f3016bc001e35 /db | |
| parent | 5b9a40ddcb538ee23101ca13ac62718e69b3881b (diff) | |
add migration to move categories from old join table to category_id on creations table.
Diffstat (limited to 'db')
| -rw-r--r-- | db/migrate/20130221134059_migrate_categories_to_tags.rb | 20 | ||||
| -rw-r--r-- | db/migrate/20140521032101_migrate_categories_from_join_table_to_creations.rb | 8 | ||||
| -rw-r--r-- | db/schema.rb | 2 |
3 files changed, 19 insertions, 11 deletions
diff --git a/db/migrate/20130221134059_migrate_categories_to_tags.rb b/db/migrate/20130221134059_migrate_categories_to_tags.rb index 44afc3fb..3ffc9e09 100644 --- a/db/migrate/20130221134059_migrate_categories_to_tags.rb +++ b/db/migrate/20130221134059_migrate_categories_to_tags.rb @@ -1,15 +1,15 @@ class MigrateCategoriesToTags < ActiveRecord::Migration def up - ["Fondant", "Butter Cream", "Tiered", "3D", "Birthday", "Wedding", "Holiday", "Theme", "Anniversary", "Baby Shower", "Naughty Cakes"].each do |category| - Creation.joins(:categories).where(:categories => {:name => category }).each do |creation| - local_creation = Creation.find(creation.id) - local_tags = local_creation.tags.map{ |tag| tag.name } - local_tags.push(category) - creation.user.tag(local_creation, :with => local_tags, :on => :tags) - local_creation.save! - end - Category.find_by_name(category).destroy if Category.find_by_name(category) - end + #["Fondant", "Butter Cream", "Tiered", "3D", "Birthday", "Wedding", "Holiday", "Theme", "Anniversary", "Baby Shower", "Naughty Cakes"].each do |category| + #Creation.joins(:categories).where(:categories => {:name => category }).each do |creation| + #local_creation = Creation.find(creation.id) + #local_tags = local_creation.tags.map{ |tag| tag.name } + #local_tags.push(category) + #creation.user.tag(local_creation, :with => local_tags, :on => :tags) + #local_creation.save! + #end + #Category.find_by_name(category).destroy if Category.find_by_name(category) + #end end def down diff --git a/db/migrate/20140521032101_migrate_categories_from_join_table_to_creations.rb b/db/migrate/20140521032101_migrate_categories_from_join_table_to_creations.rb new file mode 100644 index 00000000..adbf45fd --- /dev/null +++ b/db/migrate/20140521032101_migrate_categories_from_join_table_to_creations.rb @@ -0,0 +1,8 @@ +class MigrateCategoriesFromJoinTableToCreations < ActiveRecord::Migration + def up + execute("UPDATE creations AS c SET category_id = cat.category_id FROM creations_categories AS cat WHERE c.id = cat.creation_id") + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index cc8bb549..fcc8945b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140520023608) do +ActiveRecord::Schema.define(version: 20140521032101) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |
