Sha256: fab317f38384fa47f33e232b9349e1d9cd7c333adccee608bbae082ce3fcdad5

Contents?: true

Size: 701 Bytes

Versions: 12

Compression:

Stored size: 701 Bytes

Contents

class ConvertEventPayloads < ActiveRecord::Migration
  class EventMigration < ActiveRecord::Base
    self.table_name = :event_capture_events

    serialize :payload
  end

  def up
    EventMigration.find_each do |event|
      next unless event.payload.respond_to?(:to_unsafe_h)

      # Use 'update_column' because with 'update' ActiveRecord will try to
      # deserialize the existing value first, and will detect that there are
      # two identical Hashes. Use 'to_unsafe_h' because otherwise all keys
      # will be deemed unsafe, having not been permitted via the strong
      # parameters API.
      event.update_column :payload, event.payload.to_unsafe_h
    end
  end

  def down
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.22.8 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.22.7 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.22.6 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.22.5 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.22.4 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.22.2 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.22.1 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.22.0 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.21.2 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.21.1 db/migrate/20160616201120_convert_event_payloads.rb
think_feel_do_engine-3.21.0 db/migrate/20160616201120_convert_event_payloads.rb