Sha256: a3c6cc427df45709705125309abe733905e16a7d097fa793ad8a47b54b075c2b

Contents?: true

Size: 895 Bytes

Versions: 14

Compression:

Stored size: 895 Bytes

Contents

class ChangeFurtherSubscribedUsersToSet < ActiveRecord::Migration
  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 %Q{
        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 %Q{
            UPDATE #{table}
            SET subscribed_users = '#{subscribed_users_set.to_yaml}'
            WHERE id = #{entity["id"]}
          }
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fat_free_crm-0.13.6 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.13.5 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.13.4 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.13.3 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.13.2 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.12.3 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.12.2 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.13.1 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.12.1 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.13.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.12.0 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.11.4 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.11.3 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb
fat_free_crm-0.11.2 db/migrate/20120405080742_change_further_subscribed_users_to_set.rb