Sha256: 66641abb2726acabd8cd004cfef5bad529bb991a28cdce431df60937f0cbb90b
Contents?: true
Size: 947 Bytes
Versions: 1
Compression:
Stored size: 947 Bytes
Contents
class MergeMarkdownRevisionsIntoPosts < ActiveRecord::Migration class Monologue::PostsRevision < ActiveRecord::Base attr_accessible :title, :content, :url, :published_at, :post_id end class Monologue::Post < ActiveRecord::Base end def up Monologue::PostsRevision.reset_column_information Monologue::Post.reset_column_information add_column :monologue_posts, :is_markdown, :boolean Monologue::Post.reset_column_information Monologue::Post.all.each do |post| latest_revision = latest_revision_for(post) post.is_markdown = latest_revision.is_markdown post.save(validate: false) end remove_column :monologue_posts_revisions, :is_markdown end def down raise ActiveRecord::IrreversibleMigration end private def latest_revision_for(post) Monologue::PostsRevision.where("post_id = ?", post.id).order("monologue_posts_revisions.updated_at DESC").limit(1).first end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
monologue-markdown-0.3.0 | db/migrate/20130913004609_merge_markdown_revisions_into_posts.rb |