about summary refs log tree commit diff stats
path: root/db/migrate/20180704125527_add_blog_drafts.rb
blob: 07c507896c40a3693ddaa9a2dc7da7ce2e9590d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class AddBlogDrafts < ActiveRecord::Migration[5.1]
  def change
    add_column :blogs, :published, :boolean, null: false, default: false
    add_column :blogs, :published_at, :datetime, null: true

    reversible do |dir|
      dir.up do
        Blog.all.each do |blog|
          blog.published = true
          blog.published_at = blog.created_at

          blog.save!
        end
      end
    end
  end
end