Sha256: 74c675858a4b6f66dc4a445056c99da687ce3b73be8b80d0c8eb6225d63e1e03

Contents?: true

Size: 717 Bytes

Versions: 3

Compression:

Stored size: 717 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', unique: true
  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

3 entries across 3 versions & 1 rubygems

Version Path
unread-0.9.0 lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb
unread-0.8.3 lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb
unread-0.8.2 lib/generators/unread/polymorphic_reader_migration/templates/unread_polymorphic_reader_migration.rb