about summary refs log tree commit diff stats
path: root/db/migrate/20180702214240_rename_entries_to_blogs.rb
blob: eac2e6ac0377b438f407d7b2405f078f539d099a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class RenameEntriesToBlogs < ActiveRecord::Migration[5.1]
  def up
    rename_table :entries, :blogs
    
    remove_column :blogs, :type
    
    Record.where(recordable_type: "Entry").each do |r|
      r.recordable_type = "Blog"
      r.save!
    end
  end
  
  def down
    rename_table :blogs, :entries
    
    add_column :entries, :type, :string, null: false, default: "Blog"
    change_column_default :entries, :type, nil
    
    Record.where(recordable_type: "Blog").each do |r|
      r.recordable_type = "Entry"
      r.save!
    end
  end
end