title: Rails migration: update_all with dynamic code is possible?
body: <p>I'd like to add a new field in a table.</p>
  
  <p>My new "secret_code" field in my User model should be equal to Digest::SHA1.hexdigest([Time.now, rand].join)[1..12].</p>
  
  <p>What I'm trying to do is generate a migration that would add the field to the table and also populate my existing users with a (sort of) unique "secret_code".</p>
  
  <pre><code>class AddSecretCodeToUsers &lt; ActiveRecord::Migration
    def self.up
      add_column :users, :secret_code, :string
      User.update_all ["secret_code =?", Digest::SHA1.hexdigest([Time.now, rand].join)[1..12]]
    end
  
    def self.down
      remove_column :users, :secret_code
    end
  end
  </code></pre>
  
  <p>The problem is that this migration populate all the existing users with the same secret code!  </p>
  
  <p>One solution would be NOT to use update_all and run a loop to fetch every user and send an update to each one, but in this case my migration would be extremely slow.</p>
  
  <p>Is there a way to send a "unique" random value to an update_all method?</p>
  
  <p>Thanks,
  Augusto </p>