Class: UnreadMigration

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

Class Method Summary collapse

Class Method Details

.create_optionsObject



16
17
18
19
20
21
22
23
# File 'lib/generators/unread/migration/templates/migration.rb', line 16

def self.create_options
  options = ''
  if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) \
    && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
    options = 'DEFAULT CHARSET=latin1'
  end
  options
end

.downObject



12
13
14
# File 'lib/generators/unread/migration/templates/migration.rb', line 12

def self.down
  drop_table ReadMark
end

.upObject



2
3
4
5
6
7
8
9
10
# File 'lib/generators/unread/migration/templates/migration.rb', line 2

def self.up
  create_table ReadMark, force: true, options: create_options do |t|
    t.references :readable, polymorphic: { null: false }
    t.references :reader,   polymorphic: { null: false }
    t.datetime :timestamp, null: false
  end

  add_index ReadMark, [:reader_id, :reader_type, :readable_type, :readable_id], name: 'read_marks_reader_readable_index', unique: true
end