Skip to content

Commit 57d835f

Browse files
author
Daniel Orner
committed
Update migration as per discussion
1 parent 983d120 commit 57d835f

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

db/migrate/20230421202218_fix_bad_user_roles.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@ def change
33
bad_roles = Role.all.select { |r| r.resource_type && r.resource.nil? }
44

55
bad_roles.each do |role|
6-
profile = Partners::Profile.find_by_id(role.resource_id)
7-
if profile.nil?
8-
next
9-
elsif profile.partner.nil?
10-
profile = Partners::Profile.find_by_id(profile.partner_id)
11-
next if profile.nil? || profile.partner.nil?
12-
end
13-
14-
role.update!(resource_id: profile.partner_id)
6+
UsersRole.where(role_id: role.id).destroy_all
7+
role.destroy
158
end
16-
179
end
1810
end

db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2023_03_16_135543) do
13+
ActiveRecord::Schema[7.0].define(version: 2023_04_21_202218) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

0 commit comments

Comments
 (0)