Remove all my page grids before migration

pull/7056/head
Oliver Günther 6 years ago
parent e2390b1d60
commit 6a07fe000f
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 14
      db/migrate/20190220080647_migrate_my_page_layout.rb
  2. 1
      modules/grids/app/models/grids/grid.rb

@ -1,6 +1,10 @@
class MigrateMyPageLayout < ActiveRecord::Migration[5.2]
def up
UserPreference.transaction do
# Remove all my page grids
::Grids::MyPage.destroy_all
user_my_page_prefs.find_each do |pref|
old_layout = pref.others.with_indifferent_access[:my_page_layout]
next unless old_layout
@ -64,7 +68,7 @@ class MigrateMyPageLayout < ActiveRecord::Migration[5.2]
start_column: 3,
end_column: 5
left_row += widget_height
right_row += widget_height
end
my_page.row_count = [left_row, right_row].max - 1
@ -84,13 +88,9 @@ class MigrateMyPageLayout < ActiveRecord::Migration[5.2]
# Get all preferences with my page set that do not have
# a grid
def user_my_page_prefs
grid_table = Grids::MyPage.table_name
pref_table = UserPreference.table_name
::UserPreference
.joins("LEFT OUTER JOIN #{grid_table} ON #{grid_table}.user_id = #{pref_table}.user_id")
.where("#{pref_table}.others LIKE '%my_page_layout%'")
.where("#{grid_table}.user_id IS NULL")
::UserPreference.where("#{pref_table}.others LIKE '%my_page_layout%'")
end
##
@ -121,7 +121,7 @@ class MigrateMyPageLayout < ActiveRecord::Migration[5.2]
issuesreportedbyme: :work_packages_created,
issueswatched: :work_packages_watched,
news: :news,
calendar: :news,
calendar: :calendar,
timelog: :time_entries_current_user,
documents: :documents
}

@ -34,6 +34,7 @@ module Grids
has_many :widgets,
class_name: 'Widget',
dependent: :destroy,
autosave: true
def self.new_default(_user)

Loading…
Cancel
Save