mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 05:02:50 +08:00
Merge pull request #2691 from aignatov-bio/ai-sci-4792-improve-repository-state-migration
Improve repository state migration [SCI-4792]
This commit is contained in:
commit
32fd8e7781
1 changed files with 22 additions and 4 deletions
|
@ -8,8 +8,22 @@ class RepositoryTableStateUpdate < ActiveRecord::Migration[6.0]
|
|||
def up
|
||||
TempStateModel.find_each do |table_state|
|
||||
state = table_state.state
|
||||
order_state = state['order'][0][0]
|
||||
state['order'][0][0] = order_state + 2 if order_state > 5
|
||||
order_state = state.dig('order', 0, 0)
|
||||
|
||||
unless order_state
|
||||
order = state.dig('order', '0')
|
||||
state['order'] = [order]
|
||||
order_state = state.dig('order', 0, 0)
|
||||
end
|
||||
|
||||
state['order'][0][0] = order_state.to_i + 2 if order_state.to_i > 5
|
||||
|
||||
if state['columns'].is_a? Hash
|
||||
columns_array = []
|
||||
state['columns'].each { |k, v| columns_array[k.to_i] = v }
|
||||
state['columns'] = columns_array
|
||||
end
|
||||
|
||||
2.times do
|
||||
state['columns'].insert(6,
|
||||
'search' => {
|
||||
|
@ -17,9 +31,13 @@ class RepositoryTableStateUpdate < ActiveRecord::Migration[6.0]
|
|||
},
|
||||
'visible' => false)
|
||||
end
|
||||
state['ColReorder'] = state['ColReorder'].map { |i| i > 5 ? i + 2 : i } + [6, 7]
|
||||
if state['ColReorder']
|
||||
state['ColReorder'] = state['ColReorder'].map { |i| i.to_i > 5 ? i.to_i + 2 : i.to_i } + [6, 7]
|
||||
end
|
||||
table_state.update(state: state)
|
||||
rescue StandardError
|
||||
# Corrupted state will be cleared and default state will be generated on load
|
||||
table_state.update(state: {})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue