Sha256: 8cba0ef719dbf4a35b7c09847d1916b2ed20b1deaf5ab8e9caf0932a844abd87

Contents?: true

Size: 945 Bytes

Versions: 13

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

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

13 entries across 13 versions & 1 rubygems

Version Path
fat_free_crm-0.22.1 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.22.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.21.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.20.1 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.20.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.19.2 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.19.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.18.2 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.17.3 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.18.1 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.18.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.17.2 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.17.1 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb