2017-06-30 16:23:28 +08:00
|
|
|
class CreateSamplesTables < ActiveRecord::Migration[4.2]
|
2016-12-05 18:08:33 +08:00
|
|
|
def change
|
|
|
|
create_table :samples_tables do |t|
|
2016-12-07 21:14:32 +08:00
|
|
|
t.jsonb :status, null: false,
|
2019-01-07 20:29:17 +08:00
|
|
|
default: if defined?(SampleDatatable)
|
|
|
|
SampleDatatable::SAMPLES_TABLE_DEFAULT_STATE
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
2016-12-05 18:08:33 +08:00
|
|
|
# Foreign keys
|
|
|
|
t.references :user, null: false
|
2017-01-26 23:30:31 +08:00
|
|
|
t.references :team, null: false
|
2016-12-05 18:08:33 +08:00
|
|
|
|
|
|
|
t.timestamps null: false
|
|
|
|
end
|
|
|
|
add_index :samples_tables, :user_id
|
2017-01-26 23:30:31 +08:00
|
|
|
add_index :samples_tables, :team_id
|
2016-12-05 18:08:33 +08:00
|
|
|
|
2019-01-07 20:29:17 +08:00
|
|
|
if defined?(SamplesTable) &&
|
|
|
|
defined?(SampleDatatable) &&
|
|
|
|
defined?(CustomField)
|
|
|
|
User.find_each do |user|
|
|
|
|
next unless user.teams
|
|
|
|
|
|
|
|
user.teams.find_each do |team|
|
|
|
|
team_status = SampleDatatable::SAMPLES_TABLE_DEFAULT_STATE.deep_dup
|
|
|
|
next unless team.custom_fields
|
2016-12-05 18:08:33 +08:00
|
|
|
|
2019-01-07 20:29:17 +08:00
|
|
|
team.custom_fields.each_with_index do |_, index|
|
|
|
|
team_status['columns'] << { 'visible' => true,
|
|
|
|
'search' => {
|
|
|
|
'search' => '',
|
|
|
|
'smart' => true,
|
|
|
|
'regex' => false,
|
|
|
|
'caseInsensitive' => true
|
|
|
|
} }
|
|
|
|
team_status['ColReorder'] << (7 + index)
|
|
|
|
end
|
|
|
|
|
|
|
|
SamplesTable.create(user: user, team: team, status: team_status)
|
|
|
|
end
|
2016-12-05 18:08:33 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|