Skip to content

Commit

Permalink
Merge pull request #16405 from opf/fix/57036/migrating-project-page
Browse files Browse the repository at this point in the history
Avoid referencing project directly in MyProjectPage migration
  • Loading branch information
aaron-contreras authored Aug 12, 2024
2 parents 3b448ed + 43e27bb commit a30060b
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class MyPageEntry < ActiveRecord::Base
serialize :top
serialize :left
serialize :right

belongs_to :project
end
# rubocop:enable Rails/ApplicationRecord

Expand Down Expand Up @@ -84,7 +82,7 @@ def add_permission
end

def create_grid(entry)
grid = Grids::Overview.new project: entry.project, column_count: 2, created_at: entry.created_on
grid = Grids::Overview.new project_id: entry.project_id, column_count: 2, created_at: entry.created_on

%i[top left right].each do |area|
entry.send(area).each do |widget|
Expand All @@ -99,9 +97,12 @@ def create_grid(entry)
end

def move_attachments(entry, grid)
Attachment
.where(container_type: "MyProjectsOverview", container_id: entry.id)
.update_all(container_type: "Grids::Grid", container_id: grid.id)
execute <<~SQL.squish
UPDATE attachments
SET container_type = 'Grids::Grid', container_id = #{grid.id}
WHERE container_type = 'MyProjectsOverview'
AND container_id = #{entry.id}
SQL
end

def build_widget(grid, widget_config, position)
Expand Down Expand Up @@ -232,7 +233,7 @@ def query(grid, identifier)
query = new_default_query name: "_",
is_public: true,
hidden: true,
project: grid.project,
project_id: grid.project_id,
user: query_user(grid)

query.add_filter(filter_name(identifier), "=", [::Queries::Filters::MeValue::KEY])
Expand All @@ -247,9 +248,7 @@ def query(grid, identifier)

def migratable_entries
MyPageEntry
.includes(:project)
.references(:projects)
.where.not(projects: { id: nil })
.where("project_id IN (SELECT id from projects)")
end

def filter_name(identifier)
Expand Down

0 comments on commit a30060b

Please sign in to comment.