From 49b11f2864f75bcfb8d0d01439939ed68aa90b8f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 2 Jul 2018 18:03:37 -0400 Subject: Collapsed Entry -> Blog single-table inheritance to Blog --- .../20180702214240_rename_entries_to_blogs.rb | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 db/migrate/20180702214240_rename_entries_to_blogs.rb (limited to 'db/migrate') 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 @@ +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 -- cgit 1.4.1