about summary refs log tree commit diff stats
path: root/db/migrate/20180702214240_rename_entries_to_blogs.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20180702214240_rename_entries_to_blogs.rb')
-rw-r--r--db/migrate/20180702214240_rename_entries_to_blogs.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/db/migrate/20180702214240_rename_entries_to_blogs.rb b/db/migrate/20180702214240_rename_entries_to_blogs.rb new file mode 100644 index 0000000..eac2e6a --- /dev/null +++ b/db/migrate/20180702214240_rename_entries_to_blogs.rb
@@ -0,0 +1,24 @@
1class RenameEntriesToBlogs < ActiveRecord::Migration[5.1]
2 def up
3 rename_table :entries, :blogs
4
5 remove_column :blogs, :type
6
7 Record.where(recordable_type: "Entry").each do |r|
8 r.recordable_type = "Blog"
9 r.save!
10 end
11 end
12
13 def down
14 rename_table :blogs, :entries
15
16 add_column :entries, :type, :string, null: false, default: "Blog"
17 change_column_default :entries, :type, nil
18
19 Record.where(recordable_type: "Blog").each do |r|
20 r.recordable_type = "Entry"
21 r.save!
22 end
23 end
24end