Sha256: 5ed110ab1b8f3138244a1c736c37c44243d52a4ac3814858da6dbd1046090377

Contents?: true

Size: 703 Bytes

Versions: 4

Compression:

Stored size: 703 Bytes

Contents

class UnreadPolymorphicReaderMigration < ActiveRecord::Migration
  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'
  end

  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unread-0.8.1 lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb
unread-0.8.0 lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb
unread-0.7.1 lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb
unread-0.7.0 lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb