  class AddProfileCompleteColumnsToUsers < ActiveRecord::Migration
    def self.up
      execute "ALTER TABLE users ADD COLUMN profile_completed_at TIMESTAMP"
      #add index on profile_completed_at
      execute "CREATE INDEX index_users_on_profile_completed_at ON users USING btree (profile_completed_at)"
      execute "ALTER TABLE users ADD COLUMN profile_complete_reminder1_sent_at TIMESTAMP"
      execute "ALTER TABLE users ADD COLUMN profile_complete_reminder2_sent_at TIMESTAMP"
      execute "ALTER TABLE users ADD COLUMN profile_complete_reminder3_sent_at TIMESTAMP"

      User.find_each(batch_size:100) do |user|
        User.where(id:user.id).update_all(profile_completed_at: Time.now)
      end
      #User.where('users.id IN (SELECT player_id FROM musicians_instruments) OR users.id IN (SELECT player_id FROM genre_players)').update_all(profile_completed_at: Time.now)
    end
    def self.down
      execute "ALTER TABLE users DROP COLUMN profile_completed_at"
      execute "ALTER TABLE users DROP COLUMN profile_complete_reminder1_sent_at"
      execute "ALTER TABLE users DROP COLUMN profile_complete_reminder2_sent_at"
      execute "ALTER TABLE users DROP COLUMN profile_complete_reminder3_sent_at"
    end
  end


