Skip to content

Commit e559b88

Browse files
committed
remove version_settings.rb
1 parent 73aa92d commit e559b88

11 files changed

Lines changed: 64 additions & 272 deletions

File tree

modules/backlogs/app/models/version_setting.rb

Lines changed: 0 additions & 38 deletions
This file was deleted.

modules/backlogs/db/migrate/20260313164539_migrate_versions_to_sprints.rb

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@
2929
#++
3030

3131
class MigrateVersionsToSprints < ActiveRecord::Migration[8.0]
32+
class MigrationVersionSetting < ApplicationRecord
33+
self.table_name = "version_settings"
34+
35+
DISPLAY_LEFT = 2
36+
DISPLAY_RIGHT = 3
37+
end
38+
39+
class MigrationWorkPackage < ApplicationRecord
40+
self.table_name = "work_packages"
41+
end
42+
43+
class MigrationVersion < ApplicationRecord
44+
self.table_name = "versions"
45+
46+
has_many :work_packages,
47+
class_name: "MigrateVersionsToSprints::MigrationWorkPackage",
48+
foreign_key: "version_id"
49+
50+
has_many :version_settings,
51+
class_name: "MigrateVersionsToSprints::MigrationVersionSetting",
52+
foreign_key: "version_id"
53+
end
54+
3255
def up
3356
return if sprint_versions_with_work_package_ids.none?
3457

@@ -50,12 +73,13 @@ def sprint_versions_with_work_package_ids
5073
# Load versions used as sprints including work package ids associated with the version.
5174
# Since the same version can be used as a sprint in one project but not in another,
5275
# the work package ids are filtered by projects where the version is used as a sprint.
53-
display_versions = [VersionSetting::DISPLAY_LEFT, VersionSetting::DISPLAY_RIGHT]
54-
Version.joins(:version_settings, :work_packages)
55-
.where(version_settings: { display: display_versions })
56-
.where("work_packages.project_id = version_settings.project_id")
57-
.group("versions.id")
58-
.select("versions.*, array_agg(DISTINCT work_packages.id) AS wp_ids")
76+
77+
MigrationVersion
78+
.joins(:version_settings, :work_packages)
79+
.where(version_settings: { display: [MigrationVersionSetting::DISPLAY_LEFT, MigrationVersionSetting::DISPLAY_RIGHT] })
80+
.where("work_packages.project_id = version_settings.project_id")
81+
.group("versions.id")
82+
.select("versions.*, array_agg(DISTINCT work_packages.id) AS wp_ids")
5983
end
6084

6185
def create_sprint(version)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class RemoveVersionSettings < ActiveRecord::Migration[8.1]
4+
def up
5+
drop_table :version_settings
6+
end
7+
8+
def down
9+
require_relative "tables/version_settings"
10+
11+
Tables::VersionSettings.table(self)
12+
end
13+
end

modules/backlogs/lib/open_project/backlogs/engine.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,15 @@ def self.settings
129129

130130
patches %i[PermittedParams
131131
WorkPackage
132-
Project
133-
Version]
132+
Project]
134133

135134
patch_with_namespace :BasicData, :SettingSeeder
136-
patch_with_namespace :DemoData, :ProjectSeeder
137135
patch_with_namespace :WorkPackages, :SetAttributesService
138136
patch_with_namespace :WorkPackages, :BaseContract
139137
patch_with_namespace :WorkPackages, :UpdateContract
140138
patch_with_namespace :API, :V3, :WorkPackages, :EagerLoading, :Checksum
141139

142140
config.to_prepare do
143-
next if Versions::BaseContract.include?(OpenProject::Backlogs::Patches::Versions::BaseContractPatch)
144-
145-
Versions::BaseContract.prepend(OpenProject::Backlogs::Patches::Versions::BaseContractPatch)
146-
147141
# Add available settings to the user preferences
148142
UserPreferences::Schema.merge!(
149143
"definitions/UserPreferences/properties",

modules/backlogs/lib/open_project/backlogs/patches/project_seeder_patch.rb

Lines changed: 0 additions & 62 deletions
This file was deleted.

modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb

Lines changed: 0 additions & 39 deletions
This file was deleted.

modules/backlogs/lib/open_project/backlogs/patches/versions/base_contract_patch.rb

Lines changed: 0 additions & 45 deletions
This file was deleted.

modules/backlogs/spec/factories/version_setting_factory.rb

Lines changed: 0 additions & 32 deletions
This file was deleted.

modules/backlogs/spec/migrations/migrate_versions_to_sprints_spec.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
require "spec_helper"
3232
require Rails.root.join("modules/backlogs/db/migrate/20260313164539_migrate_versions_to_sprints")
33+
require Rails.root.join("modules/backlogs/db/migrate/20260420160236_remove_version_settings")
3334

3435
RSpec.describe MigrateVersionsToSprints, type: :model do
3536
subject(:migrate) { ActiveRecord::Migration.suppress_messages { described_class.migrate(:up) } }
@@ -46,11 +47,26 @@
4647

4748
def use_version(as:, version: self.version, project: self.project)
4849
display = case as
49-
when :sprint then VersionSetting::DISPLAY_LEFT
50-
when :backlog then VersionSetting::DISPLAY_RIGHT
51-
else VersionSetting::DISPLAY_NONE
50+
when :sprint then 2
51+
when :backlog then 3
52+
else 1
5253
end
53-
create(:version_setting, version:, project:, display:)
54+
55+
ActiveRecord::Migration.suppress_messages do
56+
ActiveRecord::Migration.execute(<<~SQL.squish)
57+
INSERT INTO version_settings
58+
(project_id, version_id, display, created_at, updated_at)
59+
VALUES (#{project.id}, #{version.id}, #{display}, NOW(), NOW())
60+
SQL
61+
end
62+
end
63+
64+
around(:all) do |example|
65+
# In this test: RemoveVersionSettings has already run.
66+
# In production: RemoveVersionSettings runs after MigrateVersionsToSprints.
67+
ActiveRecord::Migration.suppress_messages { RemoveVersionSettings.migrate(:down) }
68+
example.run
69+
ActiveRecord::Migration.suppress_messages { RemoveVersionSettings.migrate(:up) }
5470
end
5571

5672
before { use_version(as: version_type) }

modules/backlogs/spec/models/version_setting_spec.rb

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)