Skip to content

Commit 14c68cc

Browse files
authored
Merge pull request #1865 from openstax/fix_role_users_migration
Fix drop RoleUsers migration so it doesn't delete everything
2 parents ce286fd + aee940a commit 14c68cc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

db/migrate/20190426205807_drop_role_role_users.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ def change
77
Entity::Role.reset_column_information
88

99
Entity::Role.find_each do |role|
10-
user_profile_id = ActiveRecord::Base.connection.execute(
10+
row = ActiveRecord::Base.connection.execute(
1111
<<-SQL.strip_heredoc
1212
SELECT "role_role_users"."user_profile_id"
1313
FROM "role_role_users"
1414
WHERE "role_role_users"."entity_role_id" = #{role.id}
1515
SQL
1616
).to_a.first
1717

18-
role.update_attribute(:user_profile_id, user_profile_id) unless user_profile_id.nil?
18+
next if row.nil?
19+
20+
role.update_attribute(:user_profile_id, row['user_profile_id'])
1921
end
2022

2123
Entity::Role.where(user_profile_id: nil).delete_all

0 commit comments

Comments
 (0)