[PATCH conductor] bug 858782: don't rely on User object hooks to create entities
Scott Seago
sseago at redhat.com
Wed Sep 19 17:24:36 UTC 2012
https://bugzilla.redhat.com/show_bug.cgi?id=858782
Now that we've changed user login to username, the entities migration
is failing -- since it's using the User model save hook to
set entities, but the model now references the new 'username'
field, which only exists after a later migration.
This patch pulls the save hook logic into the migration itself and
uses the attributes as they existed at the time of this migration.
---
src/db/migrate/20120514131500_create_entities.rb | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/db/migrate/20120514131500_create_entities.rb b/src/db/migrate/20120514131500_create_entities.rb
index 1270ffe..c898120 100644
--- a/src/db/migrate/20120514131500_create_entities.rb
+++ b/src/db/migrate/20120514131500_create_entities.rb
@@ -25,10 +25,18 @@ class CreateEntities < ActiveRecord::Migration
end
User.all.each do |u|
- u.save!
+ unless u.entity
+ entity = Entity.new(:entity_target => u)
+ entity.name = "#{u.first_name} #{u.last_name} (#{u.login})"
+ entity.save!
+ end
end
UserGroup.all.each do |ug|
- ug.save!
+ unless ug.entity
+ entity = Entity.new(:entity_target => ug)
+ entity.name = "#{ug.name} (#{ug.membership_source})"
+ entity.save!
+ end
end
end
--
1.7.11.4
More information about the aeolus-devel
mailing list