Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Incorporated feedback from Oliver and Wieland: Simplified already_exists query

Frank Bergmann78a0966d0542
diff --git a/db/migrate/migration_utils/permission_adder.rb b/db/migrate/migration_utils/permission_adder.rb
index cb610647fe3..049a33eb60b 100644
--- a/db/migrate/migration_utils/permission_adder.rb
+++ b/db/migrate/migration_utils/permission_adder.rb
@@ -36,10 +36,8 @@ module Migration
.references(:role_permissions)
.find_each do |role|
# Check if the add-permission already exists before adding
- already_exists = Role
- .joins(:role_permissions)
- .where(role_permissions: { permission: add.to_s })
- .exists?(roles: { id: role.id })
+ already_exists = RolePermission
+ .exists?(role_id: role.id, permission: add.to_s)
unless already_exists
role.add_permission! add
end