Class: CreateCompactChannel

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/solid_cable/update/templates/db/migrate/create_compact_channel.rb

Instance Method Summary collapse

Instance Method Details

#downObject



15
16
17
18
19
# File 'lib/generators/solid_cable/update/templates/db/migrate/create_compact_channel.rb', line 15

def down
  change_column :solid_cable_messages, :channel, :text
  remove_column :solid_cable_messages, :channel_hash, if_exists: true
  change_column :solid_cable_messages, :payload, :text
end

#upObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/generators/solid_cable/update/templates/db/migrate/create_compact_channel.rb', line 4

def up
  change_column :solid_cable_messages, :channel, :binary, limit: 1024, null: false
  add_column :solid_cable_messages, :channel_hash, :integer, limit: 8, if_not_exists: true
  add_index :solid_cable_messages, :channel_hash, if_not_exists: true
  change_column :solid_cable_messages, :payload, :binary, limit: 536_870_912, null: false

  SolidCable::Message.find_each do |msg|
    msg.update(channel_hash: SolidCable::Message.channel_hash_for(msg.channel))
  end
end