From 2da0a6c6bf33cb9f2db6bdaf2414965ffc90b311 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Fri, 26 Jun 2020 14:31:10 +0200 Subject: [PATCH 1/3] Improve repository state migration --- ...622155632_repository_table_state_update.rb | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/db/migrate/20200622155632_repository_table_state_update.rb b/db/migrate/20200622155632_repository_table_state_update.rb index 92f797946..dfe391066 100644 --- a/db/migrate/20200622155632_repository_table_state_update.rb +++ b/db/migrate/20200622155632_repository_table_state_update.rb @@ -7,18 +7,36 @@ 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 - 2.times do - state['columns'].insert(6, - 'search' => { - 'regex' => false, 'smart' => true, 'search' => '', 'caseInsensitive' => true - }, - 'visible' => false) + begin + state = table_state.state + 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'].class == 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' => { + 'regex' => false, 'smart' => true, 'search' => '', 'caseInsensitive' => true + }, + 'visible' => false) + end + state['ColReorder'] = state['ColReorder'].map { |i| i.to_i > 5 ? i.to_i + 2 : i.to_i } + [6, 7] if state['ColReorder'] + table_state.update(state: state) + rescue + next end - state['ColReorder'] = state['ColReorder'].map { |i| i > 5 ? i + 2 : i } + [6, 7] - table_state.update(state: state) end end end From 6c7edbb9be693ff536af4ce2bf781624c20a4891 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Fri, 26 Jun 2020 14:32:55 +0200 Subject: [PATCH 2/3] Fix markup --- ...622155632_repository_table_state_update.rb | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/db/migrate/20200622155632_repository_table_state_update.rb b/db/migrate/20200622155632_repository_table_state_update.rb index dfe391066..813bee094 100644 --- a/db/migrate/20200622155632_repository_table_state_update.rb +++ b/db/migrate/20200622155632_repository_table_state_update.rb @@ -7,37 +7,36 @@ class RepositoryTableStateUpdate < ActiveRecord::Migration[6.0] def up TempStateModel.find_each do |table_state| - begin - state = table_state.state + state = table_state.state + 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) - - 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'].class == 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' => { - 'regex' => false, 'smart' => true, 'search' => '', 'caseInsensitive' => true - }, - 'visible' => false) - end - state['ColReorder'] = state['ColReorder'].map { |i| i.to_i > 5 ? i.to_i + 2 : i.to_i } + [6, 7] if state['ColReorder'] - table_state.update(state: state) - rescue - next end + + state['order'][0][0] = order_state.to_i + 2 if order_state.to_i > 5 + + if state['columns'].class == 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' => { + 'regex' => false, 'smart' => true, 'search' => '', 'caseInsensitive' => true + }, + 'visible' => false) + end + 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 + next end end end - From c479c6100cfc51c02f41af17f209c4d7442e0f92 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Wed, 1 Jul 2020 12:49:24 +0200 Subject: [PATCH 3/3] Clear table state on error --- db/migrate/20200622155632_repository_table_state_update.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db/migrate/20200622155632_repository_table_state_update.rb b/db/migrate/20200622155632_repository_table_state_update.rb index 813bee094..c394ff786 100644 --- a/db/migrate/20200622155632_repository_table_state_update.rb +++ b/db/migrate/20200622155632_repository_table_state_update.rb @@ -18,7 +18,7 @@ class RepositoryTableStateUpdate < ActiveRecord::Migration[6.0] state['order'][0][0] = order_state.to_i + 2 if order_state.to_i > 5 - if state['columns'].class == Hash + if state['columns'].is_a? Hash columns_array = [] state['columns'].each { |k, v| columns_array[k.to_i] = v } state['columns'] = columns_array @@ -36,7 +36,8 @@ class RepositoryTableStateUpdate < ActiveRecord::Migration[6.0] end table_state.update(state: state) rescue StandardError - next + # Corrupted state will be cleared and default state will be generated on load + table_state.update(state: {}) end end end