Sha256: edf71437779043a9a177e73f7b65eacb9066b0c3d4b6f0fa20f806ec088d4118

Contents?: true

Size: 914 Bytes

Versions: 8

Compression:

Stored size: 914 Bytes

Contents

class ChangeFurtherSubscribedUsersToSet < ActiveRecord::Migration[4.2]
  def up
    # Change the other tables that were missing from the previous migration
    %w[campaigns opportunities leads tasks accounts].each do |table|
      entities = connection.select_all %(
        SELECT id, subscribed_users
        FROM #{table}
        WHERE subscribed_users IS NOT NULL
            )

      puts "#{table}: Converting #{entities.size} subscribed_users arrays into sets..." unless entities.empty?

      # Run as one atomic action.
      ActiveRecord::Base.transaction do
        entities.each do |entity|
          subscribed_users_set = Set.new(YAML.load(entity["subscribed_users"]))

          connection.execute %(
            UPDATE #{table}
            SET subscribed_users = '#{subscribed_users_set.to_yaml}'
            WHERE id = #{entity['id']}
                    )
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fat_free_crm-0.15.2 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.16.4 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.15.1 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.16.3 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.16.2 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.16.1 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.16.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.15.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb