Mercurial > hg > soundsoftware-site
annotate db/migrate/.svn/text-base/101_populate_changesets_user_id.rb.svn-base @ 69:dc22c3eb3c81 luisf
Feature #35:
- Does not show the label "My Projects" if the user does not have any projects.
- If the user is not signed in only shows the default Projects list.
author | luisf |
---|---|
date | Mon, 06 Dec 2010 18:12:52 +0000 |
parents | 513646585e45 |
children |
rev | line source |
---|---|
Chris@0 | 1 class PopulateChangesetsUserId < ActiveRecord::Migration |
Chris@0 | 2 def self.up |
Chris@0 | 3 committers = Changeset.connection.select_values("SELECT DISTINCT committer FROM #{Changeset.table_name}") |
Chris@0 | 4 committers.each do |committer| |
Chris@0 | 5 next if committer.blank? |
Chris@0 | 6 if committer.strip =~ /^([^<]+)(<(.*)>)?$/ |
Chris@0 | 7 username, email = $1.strip, $3 |
Chris@0 | 8 u = User.find_by_login(username) |
Chris@0 | 9 u ||= User.find_by_mail(email) unless email.blank? |
Chris@0 | 10 Changeset.update_all("user_id = #{u.id}", ["committer = ?", committer]) unless u.nil? |
Chris@0 | 11 end |
Chris@0 | 12 end |
Chris@0 | 13 end |
Chris@0 | 14 |
Chris@0 | 15 def self.down |
Chris@0 | 16 Changeset.update_all('user_id = NULL') |
Chris@0 | 17 end |
Chris@0 | 18 end |