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

Autofix some style issues.

Pavel Balashov0905809ea668
diff --git a/db/migrate/20171106074835_move_hashed_token_to_core.rb b/db/migrate/20171106074835_move_hashed_token_to_core.rb
index dd4886319d3..1cabf8d6bd8 100644
--- a/db/migrate/20171106074835_move_hashed_token_to_core.rb
+++ b/db/migrate/20171106074835_move_hashed_token_to_core.rb
@@ -27,7 +27,7 @@
#++
class MoveHashedTokenToCore < ActiveRecord::Migration[5.1]
- class OldToken < ActiveRecord::Base
+ class OldToken < ApplicationRecord
self.table_name = :plaintext_tokens
end
diff --git a/db/migrate/20180830120550_migrate_light_background_themes.rb b/db/migrate/20180830120550_migrate_light_background_themes.rb
index dd2f97fab18..e7ad7f59ff4 100644
--- a/db/migrate/20180830120550_migrate_light_background_themes.rb
+++ b/db/migrate/20180830120550_migrate_light_background_themes.rb
@@ -68,7 +68,7 @@ class MigrateLightBackgroundThemes < ActiveRecord::Migration[5.1]
end
def set_variable(variable_name, hexcode)
- DesignColor.create(variable: variable_name, hexcode: hexcode)
+ DesignColor.create(variable: variable_name, hexcode:)
end
def apply?
diff --git a/db/migrate/20190124081710_remove_accessibility_mode.rb b/db/migrate/20190124081710_remove_accessibility_mode.rb
index 4322e194c74..ef7d8fefeef 100644
--- a/db/migrate/20190124081710_remove_accessibility_mode.rb
+++ b/db/migrate/20190124081710_remove_accessibility_mode.rb
@@ -35,7 +35,7 @@ class RemoveAccessibilityMode < ActiveRecord::Migration[5.2]
private
def delete_accessibility_mode_from_settings
- delete <<-SQL
+ delete <<-SQL.squish
DELETE FROM settings
WHERE name = 'accessibility_mode_for_anonymous'
SQL
diff --git a/db/migrate/20190220080647_migrate_my_page_layout.rb b/db/migrate/20190220080647_migrate_my_page_layout.rb
index 16f2234cef5..06f6e8c01fe 100644
--- a/db/migrate/20190220080647_migrate_my_page_layout.rb
+++ b/db/migrate/20190220080647_migrate_my_page_layout.rb
@@ -55,7 +55,7 @@ class MigrateMyPageLayout < ActiveRecord::Migration[5.2]
##
# Migrate a single preference entry and remove the my page
def migrate_my_page(user_id, old_layout)
- my_page = ::Grids::MyPage.new user_id: user_id, column_count: 4
+ my_page = ::Grids::MyPage.new user_id:, column_count: 4
# Migrate top
start_row = 1
@@ -64,7 +64,7 @@ class MigrateMyPageLayout < ActiveRecord::Migration[5.2]
(old_layout['top'] || []).each do |block|
map_widget my_page,
old_name: block,
- start_row: start_row,
+ start_row:,
end_row: start_row + widget_height,
start_column: 1,
end_column: 5
@@ -132,10 +132,10 @@ class MigrateMyPageLayout < ActiveRecord::Migration[5.2]
my_page.widgets << Grids::Widget.new(
identifier: mapping,
- start_row: start_row,
- end_row: end_row,
- start_column: start_column,
- end_column: end_column
+ start_row:,
+ end_row:,
+ start_column:,
+ end_column:
)
end
diff --git a/db/migrate/20190502102512_ensure_postgres_index_names.rb b/db/migrate/20190502102512_ensure_postgres_index_names.rb
index 323950cd87c..51f256b4d50 100644
--- a/db/migrate/20190502102512_ensure_postgres_index_names.rb
+++ b/db/migrate/20190502102512_ensure_postgres_index_names.rb
@@ -30,7 +30,7 @@ class EnsurePostgresIndexNames < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
def up
- sql = <<~SQL
+ sql = <<~SQL.squish
SELECT
FORMAT('%s_pkey', table_name) as new_name,
constraint_name as old_name
diff --git a/db/migrate/20190710132957_rename_my_page_widgets.rb b/db/migrate/20190710132957_rename_my_page_widgets.rb
index f8b4aba2a4f..87834d43ae2 100644
--- a/db/migrate/20190710132957_rename_my_page_widgets.rb
+++ b/db/migrate/20190710132957_rename_my_page_widgets.rb
@@ -62,11 +62,11 @@ class RenameMyPageWidgets < ActiveRecord::Migration[5.2]
def update_table_widget(widget, filter_name)
widget.options = {
- "name": I18n.t("js.grid.widgets.#{widget.identifier}.title"),
- "queryProps": {
- "columns[]": %w(id project type subject),
- "filters": JSON.dump([{ "status": { "operator": "o", "values": [] } },
- { filter_name => { "operator": "=", "values": ["me"] } }])
+ name: I18n.t("js.grid.widgets.#{widget.identifier}.title"),
+ queryProps: {
+ 'columns[]': %w(id project type subject),
+ filters: JSON.dump([{ status: { operator: "o", values: [] } },
+ { filter_name => { operator: "=", values: ["me"] } }])
}
}
widget.identifier = 'work_packages_table'
@@ -76,7 +76,7 @@ class RenameMyPageWidgets < ActiveRecord::Migration[5.2]
def update_widget_name(widget)
widget.options = {
- "name": I18n.t("js.grid.widgets.#{widget.identifier}.title")
+ name: I18n.t("js.grid.widgets.#{widget.identifier}.title")
}
widget.save(validate: false)
@@ -85,11 +85,11 @@ class RenameMyPageWidgets < ActiveRecord::Migration[5.2]
def update_query_widget(widget)
query_id = widget.options['queryId']
- name = Query.where(id: query_id).limit(1).pluck(:name).first || I18n.t('js.grid.widgets.work_packages_table.title')
+ name = Query.where(id: query_id).limit(1).pick(:name) || I18n.t('js.grid.widgets.work_packages_table.title')
widget.options = {
- "name": name,
- "queryId": query_id
+ name:,
+ queryId: query_id
}
widget.save(validate: false)
diff --git a/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb b/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb
index 8d93699c5f6..f7a033cfc55 100644
--- a/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb
+++ b/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb
@@ -27,7 +27,7 @@
#++
class AddDerivedEstimatedHoursToWorkPackages < ActiveRecord::Migration[5.2]
- class WorkPackageWithRelations < ActiveRecord::Base
+ class WorkPackageWithRelations < ApplicationRecord
self.table_name = "work_packages"
scope :with_children, ->(*_args) do
@@ -67,31 +67,31 @@ class AddDerivedEstimatedHoursToWorkPackages < ActiveRecord::Migration[5.2]
# for parent work packages separately while the UpdateAncestorsService
# only touches the derived_estimated_hours column.
def migrate_to_derived_estimated_hours!
- last_id = Journal.order(id: :desc).limit(1).pluck(:id).first || 0
+ last_id = Journal.order(id: :desc).limit(1).pick(:id) || 0
work_packages = WorkPackageWithRelations.with_children.where("estimated_hours > ?", 0)
work_packages.update_all("derived_estimated_hours = estimated_hours, estimated_hours = NULL")
work_packages = WorkPackageWithRelations.with_children.where("derived_estimated_hours > ?", 0)
create_journals_for work_packages
- create_work_package_journals last_id: last_id
- create_customizable_journals last_id: last_id
- create_attachable_journals last_id: last_id
+ create_work_package_journals(last_id:)
+ create_customizable_journals(last_id:)
+ create_attachable_journals(last_id:)
touch_work_packages work_packages # to invalidate cache
end
def rollback_from_derived_estimated_hours!
- last_id = Journal.order(id: :desc).limit(1).pluck(:id).first || 0
+ last_id = Journal.order(id: :desc).limit(1).pick(:id) || 0
work_packages = WorkPackageWithRelations.with_children.where("derived_estimated_hours > ?", 0)
work_packages.update_all("estimated_hours = derived_estimated_hours, derived_estimated_hours = NULL")
work_packages = WorkPackageWithRelations.with_children.where("estimated_hours > ?", 0)
create_journals_for work_packages, notes: rollback_notes
- create_work_package_journals last_id: last_id
- create_customizable_journals last_id: last_id
- create_attachable_journals last_id: last_id
+ create_work_package_journals(last_id:)
+ create_customizable_journals(last_id:)
+ create_attachable_journals(last_id:)
touch_work_packages work_packages # to invalidate cache
end
diff --git a/db/migrate/20190724093332_add_journal_versions_table.rb b/db/migrate/20190724093332_add_journal_versions_table.rb
index cd609733a8d..ca75eac5a73 100644
--- a/db/migrate/20190724093332_add_journal_versions_table.rb
+++ b/db/migrate/20190724093332_add_journal_versions_table.rb
@@ -41,7 +41,7 @@ class AddJournalVersionsTable < ActiveRecord::Migration[5.2]
unique: true
end
- ActiveRecord::Base.connection.execute <<-SQL
+ ActiveRecord::Base.connection.execute <<-SQL.squish
INSERT INTO journal_versions (journable_type, journable_id, version)
(SELECT
journable_type, journable_id, MAX(version)
diff --git a/db/migrate/20190923123858_simplify_project_active_and_timestamp.rb b/db/migrate/20190923123858_simplify_project_active_and_timestamp.rb
index f36a06fa7b2..3ec05625b9b 100644
--- a/db/migrate/20190923123858_simplify_project_active_and_timestamp.rb
+++ b/db/migrate/20190923123858_simplify_project_active_and_timestamp.rb
@@ -30,7 +30,7 @@ class SimplifyProjectActiveAndTimestamp < ActiveRecord::Migration[6.0]
STATUS_ACTIVE = 1
STATUS_ARCHIVED = 9
- class Project < ActiveRecord::Base; end
+ class Project < ApplicationRecord; end
def change
change_project_columns
@@ -56,7 +56,8 @@ class SimplifyProjectActiveAndTimestamp < ActiveRecord::Migration[6.0]
end
def fill_active_column
- add_column :projects, :active, :boolean, default: true, index: true, null: false
+ add_column :projects, :active, :boolean, default: true, null: false
+ add_index :projects, :active
Project.reset_column_information
Project.where(status: STATUS_ARCHIVED).update_all(active: false)
diff --git a/db/migrate/20191106132533_make_system_user_active.rb b/db/migrate/20191106132533_make_system_user_active.rb
index 918d07fa336..c3abf136232 100644
--- a/db/migrate/20191106132533_make_system_user_active.rb
+++ b/db/migrate/20191106132533_make_system_user_active.rb
@@ -28,7 +28,7 @@
class MakeSystemUserActive < ActiveRecord::Migration[6.0]
# Remember the integer mapped to previous builtin status
- BUILTIN_STATUS ||= 0
+ BUILTIN_STATUS = 0
def up
Principal.where(status: BUILTIN_STATUS).update_all(status: Principal.statuses[:active])
diff --git a/db/migrate/20191216135213_join_table_for_active_activities.rb b/db/migrate/20191216135213_join_table_for_active_activities.rb
index 4e22619a4dd..217cedacf55 100644
--- a/db/migrate/20191216135213_join_table_for_active_activities.rb
+++ b/db/migrate/20191216135213_join_table_for_active_activities.rb
@@ -27,11 +27,11 @@
#++
class JoinTableForActiveActivities < ActiveRecord::Migration[6.0]
- class ActivitiesJoinTable < ActiveRecord::Base
+ class ActivitiesJoinTable < ApplicationRecord
self.table_name = :time_entry_activities_projects
end
- class TimeEntryActivity < ActiveRecord::Base
+ class TimeEntryActivity < ApplicationRecord
self.table_name = :enumerations
end
@@ -66,7 +66,7 @@ class JoinTableForActiveActivities < ActiveRecord::Migration[6.0]
# existing projects.
def delete_invalid_project_activities
ActiveRecord::Base.connection.exec_query(
- <<-SQL
+ <<-SQL.squish
DELETE FROM enumerations
USING enumerations AS enums
LEFT OUTER JOIN projects on enums.project_id = projects.id
@@ -77,7 +77,7 @@ class JoinTableForActiveActivities < ActiveRecord::Migration[6.0]
def link_time_entries_to_root_activities
ActiveRecord::Base.connection.exec_query(
- <<-SQL
+ <<-SQL.squish
UPDATE
time_entries te_sink
SET
@@ -93,7 +93,7 @@ class JoinTableForActiveActivities < ActiveRecord::Migration[6.0]
def link_time_entries_to_project_activities
ActiveRecord::Base.connection.exec_query(
- <<-SQL
+ <<-SQL.squish
UPDATE
time_entries te_sink
SET
@@ -113,7 +113,7 @@ class JoinTableForActiveActivities < ActiveRecord::Migration[6.0]
.where
.not(parent_id: nil)
.pluck(:project_id, :parent_id, :active)
- .map { |project_id, parent_id, active| { project_id: project_id, activity_id: parent_id, active: active } }
+ .map { |project_id, parent_id, active| { project_id:, activity_id: parent_id, active: } }
ActivitiesJoinTable.insert_all(values) if values.present?
end
@@ -124,7 +124,7 @@ class JoinTableForActiveActivities < ActiveRecord::Migration[6.0]
def create_project_specific_activities
ActiveRecord::Base.connection.exec_query(
- <<-SQL
+ <<-SQL.squish
INSERT INTO enumerations (name, is_default, type, position, parent_id, project_id, active, created_at, updated_at)
SELECT
tea.name,
diff --git a/db/migrate/20200115090742_fix_parent_id_for_wiki_pages.rb b/db/migrate/20200115090742_fix_parent_id_for_wiki_pages.rb
index c2cff5ead0a..49c2c4c2015 100644
--- a/db/migrate/20200115090742_fix_parent_id_for_wiki_pages.rb
+++ b/db/migrate/20200115090742_fix_parent_id_for_wiki_pages.rb
@@ -27,7 +27,7 @@
#++
class FixParentIdForWikiPages < ActiveRecord::Migration[6.0]
- class MyWikiPages < ActiveRecord::Base
+ class MyWikiPages < ApplicationRecord
self.table_name = "wiki_pages"
end
diff --git a/db/migrate/20200217155632_rename_tokens.rb b/db/migrate/20200217155632_rename_tokens.rb
index 41be5626b53..46bd72a54fa 100644
--- a/db/migrate/20200217155632_rename_tokens.rb
+++ b/db/migrate/20200217155632_rename_tokens.rb
@@ -27,7 +27,7 @@
#++
class RenameTokens < ActiveRecord::Migration[6.0]
- class Token < ActiveRecord::Base
+ class Token < ApplicationRecord
end
def up
diff --git a/db/migrate/20200302100431_fix_attachable_journals.rb b/db/migrate/20200302100431_fix_attachable_journals.rb
index 77260a6d99f..b8970b34327 100644
--- a/db/migrate/20200302100431_fix_attachable_journals.rb
+++ b/db/migrate/20200302100431_fix_attachable_journals.rb
@@ -34,7 +34,7 @@ class FixAttachableJournals < ActiveRecord::Migration[6.0]
# This does not fix journals where the attachment has been deleted in the meantime as
# we no longer have the necessary information to recreate the journals.
def up
- statement = <<~SQL
+ statement = <<~SQL.squish
WITH
existing_attachments AS (
SELECT
diff --git a/db/migrate/20200326102408_rename_fixed_version.rb b/db/migrate/20200326102408_rename_fixed_version.rb
index 786bad66fe5..c1430f1d051 100644
--- a/db/migrate/20200326102408_rename_fixed_version.rb
+++ b/db/migrate/20200326102408_rename_fixed_version.rb
@@ -43,7 +43,7 @@ class RenameFixedVersion < ActiveRecord::Migration[6.0]
def rename_query_attributes(from, to)
ActiveRecord::Base.connection.exec_query(
- <<-SQL
+ <<-SQL.squish
UPDATE
queries q_sink
SET
diff --git a/db/migrate/20200522131255_splash_multi_list_customizable_journals.rb b/db/migrate/20200522131255_splash_multi_list_customizable_journals.rb
index 860e6e0d849..e050cdea616 100644
--- a/db/migrate/20200522131255_splash_multi_list_customizable_journals.rb
+++ b/db/migrate/20200522131255_splash_multi_list_customizable_journals.rb
@@ -33,7 +33,7 @@ class SplashMultiListCustomizableJournals < ActiveRecord::Migration[6.0]
# be returned as three rows with the value_part `1`, `2` and `3` respectively.
# Those are then inserted into the journals table.
# Lastly, the entries with the unsplashed values are deleted.
- execute <<~SQL
+ execute <<~SQL.squish
WITH existing_journals AS (
SELECT *
FROM (
@@ -76,7 +76,7 @@ class SplashMultiListCustomizableJournals < ActiveRecord::Migration[6.0]
# Lastly, all customizable_journals entries that where not just created and that belong to a group of more than one
# value per journal and custom field are deleted.
def down
- execute <<~SQL
+ execute <<~SQL.squish
WITH aggregated_value AS (
SELECT
journal_id,
diff --git a/db/migrate/20200625133727_fix_inherited_group_member_roles.rb b/db/migrate/20200625133727_fix_inherited_group_member_roles.rb
index eb9748af7b5..101687dd906 100644
--- a/db/migrate/20200625133727_fix_inherited_group_member_roles.rb
+++ b/db/migrate/20200625133727_fix_inherited_group_member_roles.rb
@@ -40,7 +40,7 @@ class FixInheritedGroupMemberRoles < ActiveRecord::Migration[6.0]
# Recreate member_roles for all group members
Groups::UpdateRolesService
.new(member.principal, current_user: SystemUser.first, contract_class: EmptyContract)
- .call(member: member, send_notifications: false)
+ .call(member:, send_notifications: false)
end
end
diff --git a/db/migrate/20200708065116_fix_members_inconsistencies.rb b/db/migrate/20200708065116_fix_members_inconsistencies.rb
index 9af0c7eb762..78d3ae166fa 100644
--- a/db/migrate/20200708065116_fix_members_inconsistencies.rb
+++ b/db/migrate/20200708065116_fix_members_inconsistencies.rb
@@ -31,7 +31,7 @@ class FixMembersInconsistencies < ActiveRecord::Migration[6.0]
change_column_default :members, :created_on, -> { 'CURRENT_TIMESTAMP' }
# Update all members without created_on which got created by CTE
- Member.where(created_on: nil).update_all(created_on: Time.now)
+ Member.where(created_on: nil).update_all(created_on: Time.zone.now)
# Delete members without member_roles
Member.includes(:member_roles).where(member_roles: { id: nil }).destroy_all
diff --git a/db/migrate/20200820140526_remove_summable_setting.rb b/db/migrate/20200820140526_remove_summable_setting.rb
index c911365b373..07dee884425 100644
--- a/db/migrate/20200820140526_remove_summable_setting.rb
+++ b/db/migrate/20200820140526_remove_summable_setting.rb
@@ -29,7 +29,7 @@
class RemoveSummableSetting < ActiveRecord::Migration[6.0]
# Do not need a down migration as we simply fall back on the default settings
def up
- execute <<~SQL
+ execute <<~SQL.squish
DELETE FROM settings WHERE name = 'work_package_list_summable_columns'
SQL
end
diff --git a/db/migrate/20200924085508_cleanup_orphaned_journal_data.rb b/db/migrate/20200924085508_cleanup_orphaned_journal_data.rb
index a676f289e76..c744139ef8d 100644
--- a/db/migrate/20200924085508_cleanup_orphaned_journal_data.rb
+++ b/db/migrate/20200924085508_cleanup_orphaned_journal_data.rb
@@ -43,7 +43,7 @@ class CleanupOrphanedJournalData < ActiveRecord::Migration[6.0]
private
def cleanup_orphaned_journals(table)
- execute <<~SQL
+ execute <<~SQL.squish
DELETE
FROM
#{table}
diff --git a/db/migrate/20200925084550_members_allow_null_on_project.rb b/db/migrate/20200925084550_members_allow_null_on_project.rb
index 83ba11b4201..26f9d1978a0 100644
--- a/db/migrate/20200925084550_members_allow_null_on_project.rb
+++ b/db/migrate/20200925084550_members_allow_null_on_project.rb
@@ -56,7 +56,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0]
private
def add_updated_at_values
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE
members
SET#{' '}
@@ -67,7 +67,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0]
def migrate_principal_roles_data
fetch_principal_roles.each do |principal_id, records|
member_id = insert_into_members(principal_id, records.first['created_at'], records.first['updated_at'])
- insert_into_member_roles(member_id, records.map { |r| r['role_id'] })
+ insert_into_member_roles(member_id, records.pluck('role_id'))
end
end
@@ -78,7 +78,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0]
end
def insert_into_members(principal_id, created_at, updated_at)
- member_id = select_all <<~SQL
+ member_id = select_all <<~SQL.squish
INSERT INTO
members(user_id, created_on, updated_at)
VALUES (#{principal_id}, '#{created_at}', '#{updated_at}')
@@ -91,7 +91,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0]
def insert_into_member_roles(member_id, role_ids)
values = role_ids.map { |role_id| "(#{member_id}, #{role_id})" }
- execute <<~SQL
+ execute <<~SQL.squish
INSERT INTO
member_roles(member_id, role_id)
VALUES #{values.join(', ')}
@@ -104,7 +104,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0]
end
def insert_into_principal_roles
- execute <<~SQL
+ execute <<~SQL.squish
INSERT INTO
principal_roles (principal_id, role_id, created_at, updated_at)
SELECT
@@ -124,7 +124,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0]
end
def delete_global_members
- execute <<~SQL
+ execute <<~SQL.squish
DELETE
FROM
members
@@ -132,7 +132,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0]
project_id IS NULL
SQL
- execute <<~SQL
+ execute <<~SQL.squish
DELETE
FROM
member_roles
diff --git a/db/migrate/20201005184411_rename_timestamps.rb b/db/migrate/20201005184411_rename_timestamps.rb
index 54627ffdf0c..5b23977b0f7 100644
--- a/db/migrate/20201005184411_rename_timestamps.rb
+++ b/db/migrate/20201005184411_rename_timestamps.rb
@@ -80,7 +80,7 @@ class RenameTimestamps < ActiveRecord::Migration[6.0]
reversible do |dir|
dir.up do
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE
#{table}
SET #{column_name} = #{from_column}
diff --git a/db/migrate/20210126112238_add_uniqueness_constrain_on_lastname_for_groups_and_placeholder_users.rb b/db/migrate/20210126112238_add_uniqueness_constrain_on_lastname_for_groups_and_placeholder_users.rb
index d5c9789453e..b51337efc4f 100644
--- a/db/migrate/20210126112238_add_uniqueness_constrain_on_lastname_for_groups_and_placeholder_users.rb
+++ b/db/migrate/20210126112238_add_uniqueness_constrain_on_lastname_for_groups_and_placeholder_users.rb
@@ -29,7 +29,7 @@
class AddUniquenessConstrainOnLastnameForGroupsAndPlaceholderUsers < ActiveRecord::Migration[6.1]
def up
# Partial unique index
- execute <<-SQL
+ execute <<-SQL.squish
CREATE UNIQUE INDEX unique_lastname_for_groups_and_placeholder_users ON
users (lastname, type)
WHERE (type = 'Group' OR type = 'PlaceholderUser');
@@ -38,7 +38,7 @@ class AddUniquenessConstrainOnLastnameForGroupsAndPlaceholderUsers < ActiveRecor
def down
# Remove unique index
- execute <<-SQL
+ execute <<-SQL.squish
DROP INDEX IF EXISTS unique_lastname_for_groups_and_placeholder_users;
SQL
end
diff --git a/db/migrate/20210331085058_migrate_sessions_unlogged.rb b/db/migrate/20210331085058_migrate_sessions_unlogged.rb
index ac0c1c21016..844e9464679 100644
--- a/db/migrate/20210331085058_migrate_sessions_unlogged.rb
+++ b/db/migrate/20210331085058_migrate_sessions_unlogged.rb
@@ -31,7 +31,7 @@ class MigrateSessionsUnlogged < ActiveRecord::Migration[6.1]
truncate :sessions
# Set the table to unlogged
- execute <<~SQL
+ execute <<~SQL.squish
ALTER TABLE "sessions" SET UNLOGGED
SQL
diff --git a/db/migrate/20210512121322_make_project_identifier_unique.rb b/db/migrate/20210512121322_make_project_identifier_unique.rb
index 504df2ad324..e43297f2cde 100644
--- a/db/migrate/20210512121322_make_project_identifier_unique.rb
+++ b/db/migrate/20210512121322_make_project_identifier_unique.rb
@@ -30,7 +30,7 @@ class MakeProjectIdentifierUnique < ActiveRecord::Migration[6.1]
def change
begin
remove_index :projects, :identifier
- rescue => e
+ rescue StandardError => e
raise <<~MESSAGE
Failed to remove an index from the OpenProject database: #{e.message}
@@ -44,7 +44,7 @@ class MakeProjectIdentifierUnique < ActiveRecord::Migration[6.1]
begin
add_index :projects, :identifier, unique: true
- rescue => e
+ rescue StandardError => e
raise "You have a duplicate project identifier in your database: #{e.message}"
end
end
diff --git a/db/migrate/20210615150558_aggregate_journals.rb b/db/migrate/20210615150558_aggregate_journals.rb
index fb6b71fb302..46068af4612 100644
--- a/db/migrate/20210615150558_aggregate_journals.rb
+++ b/db/migrate/20210615150558_aggregate_journals.rb
@@ -80,7 +80,7 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
end
def update_journal_notes(mismatched_journal)
- sql = <<~SQL
+ sql = <<~SQL.squish
UPDATE journals
SET notes = :notes
WHERE id = :id
@@ -218,7 +218,7 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
# The journals that are considered for aggregation can also be reduced by providing a subselect. Doing so, one
# can e.g. consider only the journals created after a certain time.
def select_sql(journals_preselection)
- <<~SQL
+ <<~SQL.squish
(#{Journal
.from(start_group_journals_select(journals_preselection))
.joins(end_group_journals_join(journals_preselection))
@@ -229,7 +229,7 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
end
def user_or_time_group_breaking_journals_subselect(journals_preselection)
- <<~SQL
+ <<~SQL.squish
SELECT
predecessor.*,
row_number() OVER (ORDER BY predecessor.journable_type, predecessor.journable_id, predecessor.version ASC) #{group_number_alias}
@@ -245,7 +245,7 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
end
def notes_journals_subselect(journals_preselection)
- <<~SQL
+ <<~SQL.squish
(SELECT
notes_journals.*
FROM #{journals_preselection} notes_journals
@@ -258,13 +258,13 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
end
def end_group_journals_join(journals_preselection)
- group_journals_join_condition = <<~SQL
+ group_journals_join_condition = <<~SQL.squish
#{start_group_journals_alias}.#{group_number_alias} = #{end_group_journals_alias}.#{group_number_alias} - 1
AND #{start_group_journals_alias}.journable_type = #{end_group_journals_alias}.journable_type
AND #{start_group_journals_alias}.journable_id = #{end_group_journals_alias}.journable_id
SQL
- end_group_journals = <<~SQL
+ end_group_journals = <<~SQL.squish
RIGHT OUTER JOIN
(#{user_or_time_group_breaking_journals_subselect(journals_preselection)}) #{end_group_journals_alias}
ON #{group_journals_join_condition}
@@ -279,14 +279,14 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
# This also works if we do not fetch the whole set of journals starting from the first journal but rather
# start somewhere within the set. This might take place e.g. when fetching only the journals that are
# created after a certain point in time which is done when displaying of the last month in the activity module.
- breaking_journals_notes_join_condition = <<~SQL
+ breaking_journals_notes_join_condition = <<~SQL.squish
COALESCE(#{start_group_journals_alias}.version, 0) + 1 <= #{notes_in_group_alias}.version
AND #{end_group_journals_alias}.version >= #{notes_in_group_alias}.version
AND #{end_group_journals_alias}.journable_type = #{notes_in_group_alias}.journable_type
AND #{end_group_journals_alias}.journable_id = #{notes_in_group_alias}.journable_id
SQL
- breaking_journals_notes = <<~SQL
+ breaking_journals_notes = <<~SQL.squish
LEFT OUTER JOIN
#{notes_journals_subselect(journals_preselection)} #{notes_in_group_alias}
ON #{breaking_journals_notes_join_condition}
@@ -296,14 +296,14 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
end
def additional_notes_in_group_join(journals_preselection)
- successor_journals_notes_join_condition = <<~SQL
+ successor_journals_notes_join_condition = <<~SQL.squish
#{notes_in_group_alias}.version < successor_notes.version
AND #{end_group_journals_alias}.version >= successor_notes.version
AND #{end_group_journals_alias}.journable_type = successor_notes.journable_type
AND #{end_group_journals_alias}.journable_id = successor_notes.journable_id
SQL
- successor_journals_notes = <<~SQL
+ successor_journals_notes = <<~SQL.squish
LEFT OUTER JOIN
#{notes_journals_subselect(journals_preselection)} successor_notes
ON #{successor_journals_notes_join_condition}
@@ -313,7 +313,7 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
end
def projection_list
- projections = <<~SQL
+ projections = <<~SQL.squish
#{end_group_journals_alias}.journable_type,
#{end_group_journals_alias}.journable_id,
#{end_group_journals_alias}.user_id,
@@ -347,7 +347,7 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
end
def attribute_projection(attribute)
- <<~SQL
+ <<~SQL.squish
CASE
WHEN successor_notes.version IS NOT NULL THEN #{notes_in_group_alias}.#{attribute}
ELSE #{end_group_journals_alias}.#{attribute} END
@@ -355,13 +355,13 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
end
def notes_id_projection
- <<~SQL
+ <<~SQL.squish
COALESCE(#{notes_in_group_alias}.id, #{end_group_journals_alias}.id)
SQL
end
def notes_projection
- <<~SQL
+ <<~SQL.squish
COALESCE(#{notes_in_group_alias}.notes, '')
SQL
end
@@ -374,7 +374,7 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
elsif journable
limit = until_version ? "AND journals.version <= #{until_version}" : ''
- <<~SQL
+ <<~SQL.squish
(
SELECT * from journals
WHERE journals.journable_id = #{journable.id}
@@ -385,7 +385,7 @@ class AggregateJournals < ActiveRecord::Migration[6.1]
else
where = until_version ? "WHERE journals.version <= #{until_version}" : ''
- <<~SQL
+ <<~SQL.squish
(SELECT * from journals #{where})
SQL
end
diff --git a/db/migrate/20210616145324_polymorphic_journal_data.rb b/db/migrate/20210616145324_polymorphic_journal_data.rb
index 982c8fc58c4..6bbb95a4c69 100644
--- a/db/migrate/20210616145324_polymorphic_journal_data.rb
+++ b/db/migrate/20210616145324_polymorphic_journal_data.rb
@@ -38,7 +38,7 @@ class PolymorphicJournalData < ActiveRecord::Migration[6.1]
add_data_and_remove_index
data_journals.each do |journal_data|
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE journals
SET data_id = data.id, data_type = '#{journal_data.name}'
FROM #{journal_data.table_name} data
@@ -53,9 +53,10 @@ class PolymorphicJournalData < ActiveRecord::Migration[6.1]
def down
data_journals.each do |journal_data|
- add_column journal_data.table_name, :journal_id, :integer, index: true
+ add_column journal_data.table_name, :journal_id, :integer
+ add_index journal_data.table_name, :journal_id
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE #{journal_data.table_name} data
SET journal_id = journals.id
FROM journals
diff --git a/db/migrate/20210618125430_authors_as_watchers.rb b/db/migrate/20210618125430_authors_as_watchers.rb
index da092d1f8b4..4a30bbb0605 100644
--- a/db/migrate/20210618125430_authors_as_watchers.rb
+++ b/db/migrate/20210618125430_authors_as_watchers.rb
@@ -34,7 +34,7 @@ class AuthorsAsWatchers < ActiveRecord::Migration[6.1]
# * the author isn't locked and has the permission to see the work package
# * member of the project in a role with the necessary permission OR
# * non member in a public project and the non member role has the necessary permission
- execute <<~SQL
+ execute <<~SQL.squish
INSERT INTO watchers (
watchable_id,
watchable_type,
diff --git a/db/migrate/20210701073944_add_digest_setting.rb b/db/migrate/20210701073944_add_digest_setting.rb
index e19803bf7bb..a864ef79a21 100644
--- a/db/migrate/20210701073944_add_digest_setting.rb
+++ b/db/migrate/20210701073944_add_digest_setting.rb
@@ -39,7 +39,7 @@ class AddDigestSetting < ActiveRecord::Migration[6.1]
# also have been added not by the migration but in the cause of the functionality
# the migration was added for.
def remove_digest_channels
- execute <<~SQL
+ execute <<~SQL.squish
DELETE FROM
notification_settings
WHERE
diff --git a/db/migrate/20210914065555_cleanup_notifications.rb b/db/migrate/20210914065555_cleanup_notifications.rb
index 4923aee6a14..2da582c378f 100644
--- a/db/migrate/20210914065555_cleanup_notifications.rb
+++ b/db/migrate/20210914065555_cleanup_notifications.rb
@@ -56,7 +56,6 @@ class CleanupNotifications < ActiveRecord::Migration[6.1]
end
end
- # rubocop:disable Metrics/AbcSize
def down
change_table :notifications, bulk: true do |t|
t.boolean :read_mail, default: false, index: true
@@ -84,5 +83,4 @@ class CleanupNotifications < ActiveRecord::Migration[6.1]
name: 'index_notification_settings_unique_project'
end
end
- # rubocop:enable Metrics/AbcSize
end
diff --git a/db/migrate/20211005135637_remove_invalid_group_users.rb b/db/migrate/20211005135637_remove_invalid_group_users.rb
index 20aaaf181ef..df267a9c9db 100644
--- a/db/migrate/20211005135637_remove_invalid_group_users.rb
+++ b/db/migrate/20211005135637_remove_invalid_group_users.rb
@@ -28,6 +28,6 @@
class RemoveInvalidGroupUsers < ActiveRecord::Migration[6.1]
def up
- GroupUser.left_outer_joins(:user).where(users: { id: nil }).destroy_all
+ GroupUser.where.missing(:user).destroy_all
end
end
diff --git a/db/migrate/20211117195121_remove_destroyed_help_texts.rb b/db/migrate/20211117195121_remove_destroyed_help_texts.rb
index 6a349251c59..bd0279cf3f3 100644
--- a/db/migrate/20211117195121_remove_destroyed_help_texts.rb
+++ b/db/migrate/20211117195121_remove_destroyed_help_texts.rb
@@ -30,7 +30,7 @@ class RemoveDestroyedHelpTexts < ActiveRecord::Migration[6.1]
def up
custom_field_ids = CustomField
.pluck(:id)
- .map { |id| "custom_field_#{id}"}
+ .map { |id| "custom_field_#{id}" }
AttributeHelpText
.where("attribute_name LIKE 'custom_field_%'")
diff --git a/db/migrate/20220818074159_fix_deleted_data_journals.rb b/db/migrate/20220818074159_fix_deleted_data_journals.rb
index 4c71397c087..ff212b424d2 100644
--- a/db/migrate/20220818074159_fix_deleted_data_journals.rb
+++ b/db/migrate/20220818074159_fix_deleted_data_journals.rb
@@ -29,7 +29,7 @@
class FixDeletedDataJournals < ActiveRecord::Migration[7.0]
def up
get_missing_journals.each do |journable_type, relation|
- puts "Cleaning up journals on #{journable_type}"
+ Rails.logger.debug { "Cleaning up journals on #{journable_type}" }
relation.find_each { |journal| fix_journal_data(journal) }
@@ -120,9 +120,9 @@ class FixDeletedDataJournals < ActiveRecord::Migration[7.0]
table_name = journal_class.table_name
relation = Journal
- .joins("LEFT OUTER JOIN #{table_name} ON journals.data_type = '#{journal_class.to_s}' AND #{table_name}.id = journals.data_id")
+ .joins("LEFT OUTER JOIN #{table_name} ON journals.data_type = '#{journal_class}' AND #{table_name}.id = journals.data_id")
.where("#{table_name}.id IS NULL")
- .where(journable_type: journable_type)
+ .where(journable_type:)
.where.not(data_type: nil) # Ignore special tenants with data_type nil errors
.order('journals.version ASC')
.includes(:journable)
diff --git a/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rb b/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rb
index 6cfb5dbf9b0..57fa697fd43 100644
--- a/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rb
+++ b/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rb
@@ -98,12 +98,10 @@ class UpdateXktToVersion8 < ActiveRecord::Migration[6.1]
end
def get_file(name)
- path = 'modules/bim/files/ifc_models/' + name + '/'
- file_name = name + '.xkt'
+ path = "modules/bim/files/ifc_models/#{name}/"
+ file_name = "#{name}.xkt"
return unless File.exist?(path + file_name)
- File.new(File.join(Rails.root,
- path,
- file_name))
+ File.new(Rails.root.join(path, file_name))
end
end
diff --git a/modules/budgets/db/migrate/20200810152654_rename_cost_object_to_budget.rb b/modules/budgets/db/migrate/20200810152654_rename_cost_object_to_budget.rb
index b0ed916fb06..a43a0af9966 100644
--- a/modules/budgets/db/migrate/20200810152654_rename_cost_object_to_budget.rb
+++ b/modules/budgets/db/migrate/20200810152654_rename_cost_object_to_budget.rb
@@ -39,31 +39,31 @@ class RenameCostObjectToBudget < ActiveRecord::Migration[6.0]
remove_column :cost_objects, :type
rename_table :cost_objects, :budgets
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE types
SET attribute_groups = REGEXP_REPLACE(attribute_groups, ' cost_object', ' budget')
WHERE attribute_groups LIKE '%cost_object%'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE role_permissions
SET permission = 'view_budgets'
WHERE permission = 'view_cost_objects'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE role_permissions
SET permission = 'edit_budgets'
WHERE permission = 'edit_cost_objects'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE journals
SET activity_type = 'budgets'
WHERE activity_type = 'cost_objects'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE attachments
SET container_type = 'Budget'
WHERE container_type = 'CostObject'
@@ -103,31 +103,31 @@ class RenameCostObjectToBudget < ActiveRecord::Migration[6.0]
rename_in_queries('budget', 'cost_object')
rename_in_cost_queries('Budget', 'CostObject')
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE attachments
SET container_type = 'CostObject'
WHERE container_type = 'Budget'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE journals
SET activity_type = 'cost_objects'
WHERE activity_type = 'budgets'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE role_permissions
SET permission = 'view_cost_objects'
WHERE permission = 'view_budgets'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE role_permissions
SET permission = 'edit_cost_objects'
WHERE permission = 'edit_budgets'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE types
SET attribute_groups = REGEXP_REPLACE(attribute_groups, ' budget', ' cost_object')
WHERE attribute_groups LIKE '%budget%'
@@ -135,7 +135,7 @@ class RenameCostObjectToBudget < ActiveRecord::Migration[6.0]
add_column :budgets, :type, :string
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE budgets SET type = 'VariableCostObject'
SQL
@@ -145,31 +145,31 @@ class RenameCostObjectToBudget < ActiveRecord::Migration[6.0]
end
def rename_in_queries(old, new)
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE queries
SET filters = REGEXP_REPLACE(filters, '#{old}_id:', '#{new}_id:')
WHERE filters LIKE '%#{old}_id%'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE queries
SET sort_criteria = REGEXP_REPLACE(sort_criteria, '#{old}', '#{new}')
WHERE sort_criteria LIKE '%#{old}%'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE queries
SET column_names = REGEXP_REPLACE(column_names, '#{old}', '#{new}')
WHERE column_names LIKE '%#{old}%'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE queries
SET group_by = REGEXP_REPLACE(group_by, '#{old}', '#{new}')
WHERE group_by LIKE '%#{old}%'
SQL
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE queries
SET timeline_labels = REGEXP_REPLACE(timeline_labels, '#{old.camelize(:lower)}', '#{new.camelize(:lower)}')
WHERE timeline_labels LIKE '%#{old.camelize(:lower)}%'
@@ -177,7 +177,7 @@ class RenameCostObjectToBudget < ActiveRecord::Migration[6.0]
end
def rename_in_cost_queries(old, new)
- execute <<~SQL
+ execute <<~SQL.squish
UPDATE cost_queries
SET serialized = REGEXP_REPLACE(serialized, '#{old}', '#{new}')
WHERE serialized LIKE '%#{old}%'
@@ -189,6 +189,6 @@ class RenameCostObjectToBudget < ActiveRecord::Migration[6.0]
table = connection.quote table_name
sql = "SELECT indexname FROM pg_indexes WHERE tablename = #{table} AND indexdef LIKE '%(id)';"
- connection.execute(sql).map { |row| row['indexname'] }.compact.first
+ connection.execute(sql).pluck('indexname').compact.first
end
end
diff --git a/modules/costs/db/migrate/20200327074416_rename_fixed_version_in_cost_query.rb b/modules/costs/db/migrate/20200327074416_rename_fixed_version_in_cost_query.rb
index 62d26277b78..ec026c5e920 100644
--- a/modules/costs/db/migrate/20200327074416_rename_fixed_version_in_cost_query.rb
+++ b/modules/costs/db/migrate/20200327074416_rename_fixed_version_in_cost_query.rb
@@ -37,7 +37,7 @@ class RenameFixedVersionInCostQuery < ActiveRecord::Migration[6.0]
def rename_query_attributes(from, to)
ActiveRecord::Base.connection.exec_query(
- <<-SQL
+ <<-SQL.squish
UPDATE
cost_queries q_sink
SET
diff --git a/modules/job_status/db/migrate/20200422105623_add_job_status.rb b/modules/job_status/db/migrate/20200422105623_add_job_status.rb
index 6a7bf6730a4..f008987da86 100644
--- a/modules/job_status/db/migrate/20200422105623_add_job_status.rb
+++ b/modules/job_status/db/migrate/20200422105623_add_job_status.rb
@@ -28,7 +28,7 @@
class AddJobStatus < ActiveRecord::Migration[6.0]
def up
- execute <<-SQL
+ execute <<-SQL.squish
CREATE TYPE delayed_job_status AS ENUM ('in_queue', 'error', 'in_process', 'success', 'failure');
SQL
@@ -46,7 +46,7 @@ class AddJobStatus < ActiveRecord::Migration[6.0]
def down
drop_table :delayed_job_statuses
- execute <<-SQL
+ execute <<-SQL.squish
DROP TYPE delayed_job_status;
SQL
end
diff --git a/modules/job_status/db/migrate/20200610124259_extend_job_status.rb b/modules/job_status/db/migrate/20200610124259_extend_job_status.rb
index 02299801658..05df41813e5 100644
--- a/modules/job_status/db/migrate/20200610124259_extend_job_status.rb
+++ b/modules/job_status/db/migrate/20200610124259_extend_job_status.rb
@@ -33,7 +33,7 @@ class ExtendJobStatus < ActiveRecord::Migration[6.0]
def change
reversible do |dir|
dir.up do
- execute <<-SQL
+ execute <<-SQL.squish
ALTER TYPE delayed_job_status ADD VALUE IF NOT EXISTS 'cancelled';
SQL
end
diff --git a/modules/two_factor_authentication/db/migrate/20120214103300_aggregated_mobile_otp_migrations.rb b/modules/two_factor_authentication/db/migrate/20120214103300_aggregated_mobile_otp_migrations.rb
index b25dc0b3a79..25790e122c5 100644
--- a/modules/two_factor_authentication/db/migrate/20120214103300_aggregated_mobile_otp_migrations.rb
+++ b/modules/two_factor_authentication/db/migrate/20120214103300_aggregated_mobile_otp_migrations.rb
@@ -26,20 +26,20 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-require Rails.root.to_s + '/db/migrate/migration_utils/migration_squasher'
-require Rails.root.to_s + '/db/migrate/migration_utils/setting_renamer'
+require "#{Rails.root}/db/migrate/migration_utils/migration_squasher"
+require "#{Rails.root}/db/migrate/migration_utils/setting_renamer"
require 'open_project/plugins/migration_mapping'
# This migration aggregates the migrations detailed in MIGRATION_FILES
class AggregatedMobileOtpMigrations < ActiveRecord::Migration[5.0]
- MIGRATION_FILES = <<-MIGRATIONS
+ MIGRATION_FILES = <<-MIGRATIONS.freeze
001_add_user_phone.rb
002_create_extended_tokens.rb
003_remove_user_phone.rb
004_add_user_verified_phone_unverified_phone.rb
MIGRATIONS
- OLD_PLUGIN_NAME = "redmine_two_factor_authentication_authentication"
+ OLD_PLUGIN_NAME = "redmine_two_factor_authentication_authentication".freeze
def up
migration_names = OpenProject::Plugins::MigrationMapping.migration_files_to_migration_names(MIGRATION_FILES, OLD_PLUGIN_NAME)
diff --git a/modules/two_factor_authentication/db/migrate/20171023190036_model_reorganization.rb b/modules/two_factor_authentication/db/migrate/20171023190036_model_reorganization.rb
index 82a6acf75db..8bac7fd7e7a 100644
--- a/modules/two_factor_authentication/db/migrate/20171023190036_model_reorganization.rb
+++ b/modules/two_factor_authentication/db/migrate/20171023190036_model_reorganization.rb
@@ -63,7 +63,7 @@ class ModelReorganization < ActiveRecord::Migration[5.0]
User.transaction do
User.find_each do |user|
phone = user.verified_phone || user.unverified_phone
- next unless phone.present?
+ next if phone.blank?
sms = ::TwoFactorAuthentication::Device::Sms.create!(
user_id: user.id,