To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 14 / 144d87a484de2d989cccbe9e992e92ab12eacca5.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (623 Bytes)
| 1 |
class PopulateChangesetsUserId < ActiveRecord::Migration |
|---|---|
| 2 |
def self.up |
| 3 |
committers = Changeset.connection.select_values("SELECT DISTINCT committer FROM #{Changeset.table_name}")
|
| 4 |
committers.each do |committer| |
| 5 |
next if committer.blank? |
| 6 |
if committer.strip =~ /^([^<]+)(<(.*)>)?$/ |
| 7 |
username, email = $1.strip, $3 |
| 8 |
u = User.find_by_login(username) |
| 9 |
u ||= User.find_by_mail(email) unless email.blank? |
| 10 |
Changeset.update_all("user_id = #{u.id}", ["committer = ?", committer]) unless u.nil?
|
| 11 |
end |
| 12 |
end |
| 13 |
end |
| 14 |
|
| 15 |
def self.down |
| 16 |
Changeset.update_all('user_id = NULL')
|
| 17 |
end |
| 18 |
end |