about summary refs log tree commit diff stats
path: root/db/migrate/20180702214240_rename_entries_to_blogs.rb
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-07-02 18:03:37 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-07-03 14:01:41 -0400
commit49b11f2864f75bcfb8d0d01439939ed68aa90b8f (patch)
treec91d0976e9cb54562aa2c19f9648235d74f14cbf /db/migrate/20180702214240_rename_entries_to_blogs.rb
parentcb01d13034ad41a29533b623cbbf7c23b37a231c (diff)
downloadthoughts-49b11f2864f75bcfb8d0d01439939ed68aa90b8f.tar.gz
thoughts-49b11f2864f75bcfb8d0d01439939ed68aa90b8f.tar.bz2
thoughts-49b11f2864f75bcfb8d0d01439939ed68aa90b8f.zip
Collapsed Entry -> Blog single-table inheritance to Blog
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