Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions db/migrate/20260828093032_migrate_inventory_table_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# frozen_string_literal: true

class MigrateInventoryTableSettings < ActiveRecord::Migration[7.2]
def up
basic_column_names = %w(
checkbox
assigned
id
name
created_at
created_by
updated_at
updated_by
archived_at
archived_by
external_id
)

default_column_state = lambda do |name|
{
colId: name,
width: nil,
hide: false,
pinned: nil,
sort: nil,
sortIndex: nil,
aggFunc: nil,
rowGroup: false,
rowGroupIndex: nil,
pivot: false,
pivotIndex: nil,
flex: nil
}
end

basic_columns = []
basic_column_names.each_with_index do |name, _index|
basic_columns << default_column_state.call(name)
end

Repository.find_each do |repository|

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockLength: Block has too many lines. [41/25]

repository_default_state = basic_columns.dup
repository.repository_columns.order(:id).find_each do |column|
repository_default_state << default_column_state.call("col_#{column.id}")
end

repository.repository_table_states.find_each do |table_state|

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockLength: Block has too many lines. [35/25]

old_state = table_state.state
columns = repository_default_state.dup

columns.each_with_index do |column, index|
column['width'] = old_state.dig('ColSizes', index)
column['hide'] = if column['colId'] == 'name' # name column is always visible
false
else
!old_state.dig('columns', index, 'visible')
end
end

order = {
column: columns[old_state.dig('order', 0, 0)]['colId'],
dir: old_state.dig('order', 0, 1)
}

reorder_columns = []

# apply order
old_state['ColReorder'].each do |old_index|
reorder_columns << columns[old_index]
end

# new column which not exist in old state
reorder_columns.unshift(default_column_state.call('active_reminders_count'))

new_state = {
columnsState: reorder_columns,
order: order,
currentViewRender: 'table',
perPage: old_state['length']
}

# Same state is used for both active and archived
UserSetting.create!(
user: table_state.user,
key: "repository_table_#{repository.id}_active_table_state",
value: new_state
)
UserSetting.create!(
user: table_state.user,
key: "repository_table_#{repository.id}_archived_table_state",
value: new_state
)
end
end
end
end
1 change: 1 addition & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10842,6 +10842,7 @@ ALTER TABLE ONLY public.projects
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
('20260828093032'),
('20260715121739'),
('20260714101739'),
('20260708142245'),
Expand Down