Created
June 17, 2016 23:08
-
-
Save alex-kovshovik/d7758cf48411a37b9d34f8702be88fce to your computer and use it in GitHub Desktop.
Rails migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MigrateToNewContentStructure < ActiveRecord::Migration | |
| FIND_EMBEDDED_RECIPE_REGEX = /!insert_recipe\((\d+)\)/ | |
| def up | |
| ActiveRecord::Base.transaction do # Just wrap the bastard in the transaction block. | |
| Recipe.all.each do |recipe| | |
| recipe.content_block = ContentBlock.create!(...) | |
| recipe.save! | |
| end | |
| BlogPost.all.each do |blog_post| | |
| replaced_markdown = replace_recipe_ids_with_content_block_ids(blog_post.body_md) # dadada long comment testing | |
| blog_post.content_block = ContentBlock.create!(...) | |
| blog_post.content_block.save! # This forces the markdown inserts to re-process. | |
| blog_post.save! | |
| end | |
| Page.all.each do |page| | |
| page.content_block = ContentBlock.create!(...) | |
| page.save! | |
| end | |
| end | |
| end | |
| def down | |
| ContentBlock.delete_all | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment