Class: UnreadPolymorphicReaderMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb

Class Method Summary collapse

Class Method Details

.downObject



10
11
12
13
14
15
# File 'lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb', line 10

def self.down
  remove_index :read_marks, name: 'read_marks_reader_readable_index'
  remove_column :read_marks, :reader_type
  rename_column :read_marks, :reader_id, :user_id
  add_index :read_marks, [:user_id, :readable_type, :readable_id]
end

.upObject



2
3
4
5
6
7
8
# File 'lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb', line 2

def self.up
  remove_index :read_marks, [:user_id, :readable_type, :readable_id]
  rename_column :read_marks, :user_id, :reader_id
  add_column :read_marks, :reader_type, :string
  execute "update read_marks set reader_type = 'User'"
  add_index :read_marks, [:reader_id, :reader_type, :readable_type, :readable_id], name: 'read_marks_reader_readable_index', unique: true
end