mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-31 09:23:38 +08:00
Switch to STI for repositories, fix cell values snapshotting [SCI-4516]
This commit is contained in:
parent
a9c3102835
commit
3a67c99982
32 changed files with 268 additions and 131 deletions
app
controllers
models
activity.rbmy_module.rbrepository.rbrepository_asset_value.rbrepository_base.rbrepository_cell.rbrepository_checklist_item.rbrepository_checklist_value.rbrepository_column.rbrepository_date_time_range_value_base.rbrepository_date_time_value_base.rbrepository_list_item.rbrepository_list_value.rbrepository_number_value.rbrepository_row.rbrepository_snapshot.rbrepository_status_item.rbrepository_status_value.rbrepository_table_state.rbrepository_text_value.rb
permissions
services
views
config
db
|
@ -164,7 +164,7 @@ class RepositoryColumnsController < ApplicationController
|
|||
end
|
||||
|
||||
def available_columns
|
||||
render json: { columns: @repository.available_columns_ids }, status: :ok
|
||||
render json: { columns: @repository.repository_columns.pluck(:id) }, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -48,7 +48,7 @@ class Activity < ApplicationRecord
|
|||
}
|
||||
|
||||
scope :repositories_joins, lambda {
|
||||
joins("LEFT JOIN repositories ON subject_type = 'Repository' AND subject_id = repositories.id")
|
||||
joins("LEFT JOIN repositories ON subject_type = 'RepositoryBase' AND subject_id = repositories.id")
|
||||
}
|
||||
|
||||
scope :reports_joins, lambda {
|
||||
|
|
|
@ -63,8 +63,7 @@ class MyModule < ApplicationRecord
|
|||
inverse_of: :my_module, dependent: :destroy
|
||||
has_many :repository_rows, through: :my_module_repository_rows
|
||||
has_many :repository_snapshots,
|
||||
-> { where(snapshot: true) },
|
||||
class_name: 'Repository',
|
||||
class_name: 'RepositorySnapshot',
|
||||
dependent: :destroy,
|
||||
inverse_of: :my_module
|
||||
has_many :user_my_modules, inverse_of: :my_module, dependent: :destroy
|
||||
|
|
|
@ -1,46 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Repository < ApplicationRecord
|
||||
class Repository < RepositoryBase
|
||||
include SearchableModel
|
||||
include SearchableByNameModel
|
||||
include RepositoryImportParser
|
||||
include Discard::Model
|
||||
|
||||
enum permission_level: Extends::SHARED_INVENTORIES_PERMISSION_LEVELS
|
||||
|
||||
attribute :discarded_by_id, :integer
|
||||
|
||||
belongs_to :team
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
has_many :repository_columns, dependent: :destroy
|
||||
has_many :repository_rows, dependent: :destroy
|
||||
has_many :repository_table_states,
|
||||
inverse_of: :repository, dependent: :destroy
|
||||
has_many :report_elements, inverse_of: :repository, dependent: :destroy
|
||||
has_many :repository_list_items, inverse_of: :repository, dependent: :destroy
|
||||
has_many :repository_checklist_items, inverse_of: :repository, dependent: :destroy
|
||||
has_many :team_repositories, inverse_of: :repository, dependent: :destroy
|
||||
has_many :teams_shared_with, through: :team_repositories, source: :team
|
||||
has_many :repository_snapshots,
|
||||
-> { unscope(where: :snapshot) },
|
||||
class_name: 'Repository',
|
||||
class_name: 'RepositorySnapshot',
|
||||
foreign_key: :parent_id,
|
||||
inverse_of: :original_repository,
|
||||
dependent: :nullify
|
||||
belongs_to :original_repository, foreign_key: :parent_id, class_name: 'Repository', inverse_of: :repository_snapshots
|
||||
belongs_to :my_module, optional: true
|
||||
|
||||
auto_strip_attributes :name, nullify: false
|
||||
validates :name,
|
||||
presence: true,
|
||||
uniqueness: { scope: :team_id, case_sensitive: false },
|
||||
length: { maximum: Constants::NAME_MAX_LENGTH },
|
||||
unless: :snapshot?
|
||||
validates :team, presence: true
|
||||
validates :created_by, presence: true
|
||||
|
||||
# Not discarded and not snapshots
|
||||
default_scope -> { kept.live }
|
||||
length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||
|
||||
scope :accessible_by_teams, lambda { |teams|
|
||||
left_outer_joins(:team_repositories)
|
||||
|
@ -55,9 +34,6 @@ class Repository < ApplicationRecord
|
|||
.distinct
|
||||
}
|
||||
|
||||
scope :live, -> { where(snapshot: false) }
|
||||
scope :snapshots, -> { unscope(where: :snapshot).where(snapshot: true) }
|
||||
|
||||
scope :used_on_task_but_unshared, lambda { |task, team|
|
||||
where(id: task.repository_rows
|
||||
.select(:repository_id))
|
||||
|
@ -153,10 +129,6 @@ class Repository < ApplicationRecord
|
|||
where('repositories.name ILIKE ?', "%#{query}%")
|
||||
end
|
||||
|
||||
def available_columns_ids
|
||||
repository_columns.pluck(:id)
|
||||
end
|
||||
|
||||
def importable_repository_fields
|
||||
fields = {}
|
||||
# First and foremost add record name
|
||||
|
|
|
@ -45,6 +45,30 @@ class RepositoryAssetValue < ApplicationRecord
|
|||
asset.save! && save!
|
||||
end
|
||||
|
||||
def snapshot!(cell_snapshot)
|
||||
value_snapshot = dup
|
||||
asset_snapshot = asset.dup
|
||||
|
||||
asset_snapshot.save!
|
||||
|
||||
asset.blob.open do |tmp_file|
|
||||
blob_snapshot = ActiveStorage::Blob.create_after_upload!(
|
||||
io: tmp_file,
|
||||
filename: asset.blob.filename,
|
||||
metadata: asset.blob.metadata
|
||||
)
|
||||
asset_snapshot.file.attach(blob_snapshot)
|
||||
end
|
||||
|
||||
value_snapshot.assign_attributes(
|
||||
repository_cell: cell_snapshot,
|
||||
asset: asset_snapshot,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value_snapshot.save!
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
value = new(attributes)
|
||||
team = value.repository_cell.repository_column.repository.team
|
||||
|
|
36
app/models/repository_base.rb
Normal file
36
app/models/repository_base.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositoryBase < ApplicationRecord
|
||||
include Discard::Model
|
||||
|
||||
self.table_name = 'repositories'
|
||||
|
||||
attribute :discarded_by_id, :integer
|
||||
|
||||
belongs_to :team
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
has_many :repository_columns, foreign_key: :repository_id, inverse_of: :repository, dependent: :destroy
|
||||
has_many :repository_rows, foreign_key: :repository_id, inverse_of: :repository, dependent: :destroy
|
||||
has_many :repository_table_states, foreign_key: :repository_id, inverse_of: :repository, dependent: :destroy
|
||||
|
||||
auto_strip_attributes :name, nullify: false
|
||||
validates :team, presence: true
|
||||
validates :created_by, presence: true
|
||||
|
||||
# Not discarded
|
||||
default_scope -> { kept }
|
||||
|
||||
def cell_preload_includes
|
||||
cell_includes = []
|
||||
repository_columns.pluck(:data_type).each do |data_type|
|
||||
cell_includes << data_type.constantize::PRELOAD_INCLUDE
|
||||
end
|
||||
cell_includes
|
||||
end
|
||||
|
||||
def destroy_discarded(discarded_by_id = nil)
|
||||
self.discarded_by_id = discarded_by_id
|
||||
destroy
|
||||
end
|
||||
handle_asynchronously :destroy_discarded, queue: :clear_discarded_repository, priority: 20
|
||||
end
|
|
@ -126,6 +126,20 @@ class RepositoryCell < ApplicationRecord
|
|||
cell
|
||||
end
|
||||
|
||||
def snapshot!(row_snapshot)
|
||||
cell_snapshot = dup
|
||||
column_snapshot = row_snapshot.repository
|
||||
.repository_columns
|
||||
.find { |c| c.parent_id == repository_column.id }
|
||||
cell_snapshot.assign_attributes(
|
||||
repository_row: row_snapshot,
|
||||
repository_column: column_snapshot,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value.snapshot!(cell_snapshot)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def repository_column_data_type
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositoryChecklistItem < ApplicationRecord
|
||||
belongs_to :repository, inverse_of: :repository_checklist_items
|
||||
belongs_to :repository_column
|
||||
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User',
|
||||
inverse_of: :created_repository_checklist_types
|
||||
|
|
|
@ -48,6 +48,22 @@ class RepositoryChecklistValue < ApplicationRecord
|
|||
save!
|
||||
end
|
||||
|
||||
def snapshot!(cell_snapshot)
|
||||
value_snapshot = dup
|
||||
item_values = repository_checklist_items.pluck(:data)
|
||||
checklist_items_snapshot = cell_snapshot.repository_column
|
||||
.repository_checklist_items
|
||||
.select { |snapshot_item| item_values.include?(snapshot_item.data) }
|
||||
|
||||
value_snapshot.assign_attributes(
|
||||
repository_cell: cell_snapshot,
|
||||
repository_checklist_items: checklist_items_snapshot,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value_snapshot.save!
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
item_ids = payload.is_a?(String) ? JSON.parse(payload) : payload
|
||||
value = new(attributes)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositoryColumn < ApplicationRecord
|
||||
belongs_to :repository
|
||||
belongs_to :repository, class_name: 'RepositoryBase'
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
has_many :repository_cells, dependent: :destroy
|
||||
has_many :repository_rows, through: :repository_cells
|
||||
|
@ -79,22 +79,46 @@ class RepositoryColumn < ApplicationRecord
|
|||
def deep_dup
|
||||
new_column = super
|
||||
|
||||
__send__("#{data_type.underscore}_deep_dup", new_column) if respond_to?("#{data_type.underscore}_deep_dup", true)
|
||||
extra_method_name = "#{data_type.underscore}_deep_dup"
|
||||
__send__(extra_method_name, new_column) if respond_to?(extra_method_name, true)
|
||||
|
||||
new_column
|
||||
end
|
||||
|
||||
def snapshot!(repository_snapshot)
|
||||
column_snapshot = deep_dup
|
||||
column_snapshot.assign_attributes(
|
||||
repository: repository_snapshot,
|
||||
parent_id: id,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
column_snapshot.save!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def repository_list_value_deep_dup(new_column)
|
||||
repository_list_items.each { |item| new_column.repository_list_items << item.deep_dup }
|
||||
repository_list_items.each do |item|
|
||||
new_item = item.deep_dup
|
||||
new_item.repository_id = nil
|
||||
new_column.repository_list_items << new_item
|
||||
end
|
||||
end
|
||||
|
||||
def repository_checklist_value_deep_dup(new_column)
|
||||
repository_checklist_items.each { |item| new_column.repository_checklist_items << item.deep_dup }
|
||||
repository_checklist_items.each do |item|
|
||||
new_item = item.deep_dup
|
||||
new_item.repository_id = nil
|
||||
new_column.repository_checklist_items << new_item
|
||||
end
|
||||
end
|
||||
|
||||
def repository_status_value_deep_dup(new_column)
|
||||
repository_status_items.each { |item| new_column.repository_status_items << item.deep_dup }
|
||||
repository_status_items.each do |item|
|
||||
new_item = item.deep_dup
|
||||
new_item.repository_id = nil
|
||||
new_column.repository_status_items << new_item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,4 +33,14 @@ class RepositoryDateTimeRangeValueBase < ApplicationRecord
|
|||
self.last_modified_by = user
|
||||
save!
|
||||
end
|
||||
|
||||
def snapshot!(cell_snapshot)
|
||||
value_snapshot = dup
|
||||
value_snapshot.assign_attributes(
|
||||
repository_cell: cell_snapshot,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value_snapshot.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,4 +24,14 @@ class RepositoryDateTimeValueBase < ApplicationRecord
|
|||
self.last_modified_by = user
|
||||
save!
|
||||
end
|
||||
|
||||
def snapshot!(cell_snapshot)
|
||||
value_snapshot = dup
|
||||
value_snapshot.assign_attributes(
|
||||
repository_cell: cell_snapshot,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value_snapshot.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
class RepositoryListItem < ApplicationRecord
|
||||
has_many :repository_list_values, inverse_of: :repository_list_item, dependent: :destroy
|
||||
belongs_to :repository, inverse_of: :repository_list_items
|
||||
belongs_to :repository_column, inverse_of: :repository_list_items
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
||||
|
|
|
@ -42,6 +42,20 @@ class RepositoryListValue < ApplicationRecord
|
|||
save!
|
||||
end
|
||||
|
||||
def snapshot!(cell_snapshot)
|
||||
value_snapshot = dup
|
||||
list_item = cell_snapshot.repository_column
|
||||
.repository_list_items
|
||||
.find { |item| item.data == repository_list_item.data }
|
||||
value_snapshot.assign_attributes(
|
||||
repository_cell: cell_snapshot,
|
||||
repository_list_item: list_item,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value_snapshot.save!
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
value = new(attributes)
|
||||
value.repository_list_item = value.repository_cell
|
||||
|
|
|
@ -28,6 +28,16 @@ class RepositoryNumberValue < ApplicationRecord
|
|||
save!
|
||||
end
|
||||
|
||||
def snapshot!(cell_snapshot)
|
||||
value_snapshot = dup
|
||||
value_snapshot.assign_attributes(
|
||||
repository_cell: cell_snapshot,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value_snapshot.save!
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
value = new(attributes)
|
||||
value.data = BigDecimal(payload)
|
||||
|
|
|
@ -4,7 +4,7 @@ class RepositoryRow < ApplicationRecord
|
|||
include SearchableModel
|
||||
include SearchableByNameModel
|
||||
|
||||
belongs_to :repository, optional: true
|
||||
belongs_to :repository, class_name: 'RepositoryBase'
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
belongs_to :last_modified_by, foreign_key: :last_modified_by_id, class_name: 'User'
|
||||
has_many :repository_cells, -> { order(:id) }, dependent: :destroy
|
||||
|
@ -36,4 +36,17 @@ class RepositoryRow < ApplicationRecord
|
|||
def editable?
|
||||
true
|
||||
end
|
||||
|
||||
def snapshot!(repository_snapshot)
|
||||
row_snapshot = dup
|
||||
row_snapshot.assign_attributes(
|
||||
repository: repository_snapshot,
|
||||
parent_id: id,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
row_snapshot.save!
|
||||
|
||||
repository_cells.each { |cell| cell.snapshot!(row_snapshot) }
|
||||
end
|
||||
end
|
||||
|
|
8
app/models/repository_snapshot.rb
Normal file
8
app/models/repository_snapshot.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositorySnapshot < RepositoryBase
|
||||
belongs_to :original_repository, foreign_key: :parent_id, class_name: 'Repository', inverse_of: :repository_snapshots
|
||||
belongs_to :my_module, optional: true
|
||||
|
||||
validates :name, presence: true, length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||
end
|
|
@ -4,7 +4,6 @@ class RepositoryStatusItem < ApplicationRecord
|
|||
validates :repository, :repository_column, :icon, presence: true
|
||||
validates :status, presence: true, length: { minimum: Constants::NAME_MIN_LENGTH,
|
||||
maximum: Constants::NAME_MAX_LENGTH }
|
||||
belongs_to :repository
|
||||
belongs_to :repository_column
|
||||
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User', optional: true,
|
||||
inverse_of: :created_repository_status_types
|
||||
|
|
|
@ -29,6 +29,20 @@ class RepositoryStatusValue < ApplicationRecord
|
|||
save!
|
||||
end
|
||||
|
||||
def snapshot!(cell_snapshot)
|
||||
value_snapshot = dup
|
||||
list_item = cell_snapshot.repository_column
|
||||
.repository_status_items
|
||||
.find { |item| item.data == repository_status_item.data }
|
||||
value_snapshot.assign_attributes(
|
||||
repository_cell: cell_snapshot,
|
||||
repository_status_item: list_item,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value_snapshot.save!
|
||||
end
|
||||
|
||||
def data
|
||||
return nil unless repository_status_item
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class RepositoryTableState < ApplicationRecord
|
||||
belongs_to :user, inverse_of: :repository_table_states
|
||||
belongs_to :repository, inverse_of: :repository_table_states
|
||||
belongs_to :repository, class_name: 'RepositoryBase', inverse_of: :repository_table_states
|
||||
|
||||
validates :user, :repository, presence: true
|
||||
end
|
||||
|
|
|
@ -31,6 +31,16 @@ class RepositoryTextValue < ApplicationRecord
|
|||
save!
|
||||
end
|
||||
|
||||
def snapshot!(cell_snapshot)
|
||||
value_snapshot = dup
|
||||
value_snapshot.assign_attributes(
|
||||
repository_cell: cell_snapshot,
|
||||
created_at: created_at,
|
||||
updated_at: updated_at
|
||||
)
|
||||
value_snapshot.save!
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
value = new(attributes)
|
||||
value.data = payload
|
||||
|
|
|
@ -10,7 +10,7 @@ Canaid::Permissions.register_for(Repository) do
|
|||
create_repository_columns)
|
||||
.each do |perm|
|
||||
can perm do |_, repository|
|
||||
!repository.snapshot?
|
||||
!repository.is_a? RepositorySnapshot
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ module Dashboard
|
|||
project_path(object_id)
|
||||
when 'Protocol'
|
||||
edit_protocol_path(object_id)
|
||||
when 'Repository'
|
||||
when 'RepositoryBase'
|
||||
repository_path(object_id)
|
||||
when 'Report'
|
||||
edit_project_report_path(recent_object[:report_project_id], object_id) if recent_object[:report_project_id]
|
||||
|
@ -130,7 +130,7 @@ module Dashboard
|
|||
elsif recent_object[:group_id].include?('prt')
|
||||
'Protocol'
|
||||
elsif recent_object[:group_id].include?('inv')
|
||||
'Repository'
|
||||
'RepositoryBase'
|
||||
elsif recent_object[:group_id].include?('rpt')
|
||||
'Report'
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Repositories
|
||||
class MyModuleAssignedSnapshotService
|
||||
class MyModuleAssigningSnapshotService
|
||||
extend Service
|
||||
|
||||
attr_reader :repository, :my_module, :user, :errors
|
||||
|
@ -17,18 +17,14 @@ module Repositories
|
|||
return self unless valid?
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
repository_snapshot = @repository.dup
|
||||
repository_snapshot.snapshot = true
|
||||
repository_snapshot = @repository.dup.becomes(RepositorySnapshot)
|
||||
repository_snapshot.type = RepositorySnapshot.name
|
||||
repository_snapshot.original_repository = @repository
|
||||
repository_snapshot.my_module = @my_module
|
||||
repository_snapshot.save!
|
||||
|
||||
@repository.repository_columns.find_each do |column|
|
||||
column_snapshot = column.deep_dup
|
||||
column_snapshot.created_at = column.created_at
|
||||
column_snapshot.updated_at = DateTime.now
|
||||
column_snapshot.repository = repository_snapshot
|
||||
column_snapshot.save!
|
||||
@repository.repository_columns.each do |column|
|
||||
column.snapshot!(repository_snapshot)
|
||||
end
|
||||
|
||||
repository_rows = @repository.repository_rows
|
||||
|
@ -36,15 +32,7 @@ module Repositories
|
|||
.where(my_module_repository_rows: { my_module: @my_module })
|
||||
|
||||
repository_rows.find_each do |original_row|
|
||||
row_snapshot = original_row.deep_dup
|
||||
row_snapshot.parent_id = original_row.id
|
||||
row_snapshot.created_at = original_row.created_at
|
||||
row_snapshot.updated_at = DateTime.now
|
||||
row_snapshot.save!
|
||||
|
||||
original_row.repository_cells.each do |cell|
|
||||
RepositoryActions::DuplicateCell.new(cell, row_snapshot, @user).call
|
||||
end
|
||||
original_row.snapshot!(repository_snapshot)
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
@errors[e.record.class.name.underscore] = e.record.errors.full_messages
|
|
@ -19,7 +19,7 @@ module RepositoryRows
|
|||
return self unless valid?
|
||||
|
||||
downstream_modules = []
|
||||
dowstream_records = {}
|
||||
downstream_records = {}
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
unassigned_rows = @repository.repository_rows
|
||||
|
@ -42,13 +42,13 @@ module RepositoryRows
|
|||
unassigned_downstream_modules.each do |downstream_module|
|
||||
next if my_module.repository_rows.include?(repository_row)
|
||||
|
||||
dowstream_records[my_module.id] = [] unless dowstream_records[downstream_module.id]
|
||||
downstream_records[my_module.id] = [] unless downstream_records[downstream_module.id]
|
||||
MyModuleRepositoryRow.create!(
|
||||
my_module: downstream_module,
|
||||
repository_row: repository_row,
|
||||
assigned_by: @user
|
||||
)
|
||||
dowstream_records[downstream_module.id] << repository_row.name
|
||||
downstream_records[downstream_module.id] << repository_row.name
|
||||
downstream_modules.push(downstream_module)
|
||||
end
|
||||
|
||||
|
@ -60,7 +60,7 @@ module RepositoryRows
|
|||
downstream_modules.uniq.each do |downstream_module|
|
||||
log_activity(downstream_module,
|
||||
repository: @repository.id,
|
||||
record_names: dowstream_records[my_module.id].join(', '))
|
||||
record_names: downstream_records[my_module.id].join(', '))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -313,6 +313,8 @@ class TeamImporter
|
|||
if activity.subject_id.present?
|
||||
if activity.subject_type == 'Team'
|
||||
activity.subject_id = team.id
|
||||
elsif activity.subject_type == 'RepositoryBase'
|
||||
activity.subject_id = @repository_mappings[activity.subject_id]
|
||||
else
|
||||
mappings = instance_variable_get("@#{activity.subject_type.underscore}_mappings")
|
||||
activity.subject_id = mappings[activity.subject_id]
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
data-copy-records="<%= repository_copy_records_path(repository) %>"
|
||||
data-direct-upload-url="<%= rails_direct_uploads_url %>"
|
||||
data-max-dropdown-length="<%= Constants::MODAL_TEXT_MAX_LENGTH %>"
|
||||
data-repository-columns-ids="<%= repository.available_columns_ids %>"
|
||||
data-repository-columns-ids="<%= repository.repository_columns.pluck(:id) %>"
|
||||
data-save-text="<%= I18n.t('general.save') %>"
|
||||
data-edit-text="<%= I18n.t('general.edit') %>"
|
||||
data-cancel-text="<%= I18n.t('general.cancel') %>"
|
||||
|
|
|
@ -124,11 +124,11 @@ class Extends
|
|||
'MyModule' => :description }
|
||||
|
||||
ACTIVITY_SUBJECT_TYPES = %w(
|
||||
Team Repository Project Experiment MyModule Result Protocol Report RepositoryRow
|
||||
Team RepositoryBase Project Experiment MyModule Result Protocol Report RepositoryRow
|
||||
).freeze
|
||||
|
||||
SEARCHABLE_ACTIVITY_SUBJECT_TYPES = %w(
|
||||
Repository RepositoryRow Project Experiment MyModule Result Protocol Step Report
|
||||
RepositoryBase RepositoryRow Project Experiment MyModule Result Protocol Step Report
|
||||
).freeze
|
||||
|
||||
ACTIVITY_SUBJECT_CHILDREN = {
|
||||
|
|
|
@ -86,6 +86,6 @@ en:
|
|||
Project: "Project"
|
||||
Experiment: "Experiment"
|
||||
MyModule: "Task"
|
||||
Repository: "Inventory"
|
||||
RepositoryBase: "Inventory"
|
||||
Protocol: "Protocol"
|
||||
Report: "Report"
|
||||
|
|
|
@ -1,13 +1,34 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddRepositorySnapshots < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_table :repositories, bulk: true do |t|
|
||||
t.boolean :snapshot, default: false
|
||||
t.bigint :parent_id, null: true
|
||||
t.bigint :my_module_id, null: true, index: true
|
||||
end
|
||||
def up
|
||||
add_column :repositories, :parent_id, :bigint, null: true
|
||||
add_reference :repositories, :my_module
|
||||
add_column :repositories, :type, :string
|
||||
|
||||
execute "UPDATE \"repositories\" SET \"type\" = 'Repository'"
|
||||
execute "UPDATE \"activities\" SET \"subject_type\" = 'RepositoryBase' WHERE \"subject_type\" = 'Repository'"
|
||||
|
||||
add_column :repository_columns, :parent_id, :bigint, null: true
|
||||
add_column :repository_rows, :parent_id, :bigint, null: true
|
||||
|
||||
remove_reference :repository_list_items, :repository, index: true, foreign_key: true
|
||||
remove_reference :repository_status_items, :repository, foreign_key: true
|
||||
remove_reference :repository_checklist_items, :repository, foreign_key: true
|
||||
end
|
||||
|
||||
def down
|
||||
add_reference :repository_list_items, :repository, index: true, foreign_key: true
|
||||
add_reference :repository_status_items, :repository, index: true, foreign_key: true
|
||||
add_reference :repository_checklist_items, :repository, index: true, foreign_key: true
|
||||
|
||||
remove_column :repository_columns, :parent_id
|
||||
remove_column :repository_rows, :parent_id
|
||||
|
||||
execute "UPDATE \"activities\" SET \"subject_type\" = 'Repository' WHERE \"subject_type\" = 'RepositoryBase'"
|
||||
|
||||
remove_column :repositories, :parent_id, :bigint, null: true
|
||||
remove_reference :repositories, :my_module
|
||||
remove_column :repositories, :type, :string
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1100,9 +1100,9 @@ CREATE TABLE public.repositories (
|
|||
updated_at timestamp without time zone,
|
||||
discarded_at timestamp without time zone,
|
||||
permission_level integer DEFAULT 0 NOT NULL,
|
||||
snapshot boolean DEFAULT false,
|
||||
parent_id bigint,
|
||||
my_module_id bigint
|
||||
my_module_id bigint,
|
||||
type character varying
|
||||
);
|
||||
|
||||
|
||||
|
@ -1201,7 +1201,6 @@ ALTER SEQUENCE public.repository_cells_id_seq OWNED BY public.repository_cells.i
|
|||
CREATE TABLE public.repository_checklist_items (
|
||||
id bigint NOT NULL,
|
||||
data character varying NOT NULL,
|
||||
repository_id bigint NOT NULL,
|
||||
repository_column_id bigint NOT NULL,
|
||||
created_by_id bigint,
|
||||
last_modified_by_id bigint,
|
||||
|
@ -1305,7 +1304,8 @@ CREATE TABLE public.repository_columns (
|
|||
data_type integer NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
metadata jsonb DEFAULT '{}'::jsonb NOT NULL
|
||||
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
parent_id bigint
|
||||
);
|
||||
|
||||
|
||||
|
@ -1405,7 +1405,6 @@ ALTER SEQUENCE public.repository_date_time_values_id_seq OWNED BY public.reposit
|
|||
|
||||
CREATE TABLE public.repository_list_items (
|
||||
id bigint NOT NULL,
|
||||
repository_id bigint,
|
||||
repository_column_id bigint,
|
||||
data text NOT NULL,
|
||||
created_by_id bigint,
|
||||
|
@ -1544,7 +1543,6 @@ CREATE TABLE public.repository_status_items (
|
|||
id bigint NOT NULL,
|
||||
status character varying NOT NULL,
|
||||
icon character varying NOT NULL,
|
||||
repository_id bigint NOT NULL,
|
||||
repository_column_id bigint NOT NULL,
|
||||
created_by_id bigint,
|
||||
last_modified_by_id bigint,
|
||||
|
@ -4862,13 +4860,6 @@ CREATE INDEX index_repository_checklist_items_on_last_modified_by_id ON public.r
|
|||
CREATE INDEX index_repository_checklist_items_on_repository_column_id ON public.repository_checklist_items USING btree (repository_column_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_checklist_items_on_repository_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_checklist_items_on_repository_id ON public.repository_checklist_items USING btree (repository_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_checklist_values_on_created_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -4946,13 +4937,6 @@ CREATE INDEX index_repository_list_items_on_last_modified_by_id ON public.reposi
|
|||
CREATE INDEX index_repository_list_items_on_repository_column_id ON public.repository_list_items USING btree (repository_column_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_list_items_on_repository_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_list_items_on_repository_id ON public.repository_list_items USING btree (repository_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_list_values_on_created_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -5044,13 +5028,6 @@ CREATE INDEX index_repository_status_items_on_last_modified_by_id ON public.repo
|
|||
CREATE INDEX index_repository_status_items_on_repository_column_id ON public.repository_status_items USING btree (repository_column_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_status_items_on_repository_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_status_items_on_repository_id ON public.repository_status_items USING btree (repository_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_status_items_on_status; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -5786,14 +5763,6 @@ CREATE INDEX index_wopi_actions_on_extension_and_action ON public.wopi_actions U
|
|||
CREATE INDEX index_zip_exports_on_user_id ON public.zip_exports USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_status_items fk_rails_00642f1707; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_status_items
|
||||
ADD CONSTRAINT fk_rails_00642f1707 FOREIGN KEY (repository_id) REFERENCES public.repositories(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: sample_custom_fields fk_rails_01916e6992; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -5826,14 +5795,6 @@ ALTER TABLE ONLY public.report_elements
|
|||
ADD CONSTRAINT fk_rails_0510000a52 FOREIGN KEY (table_id) REFERENCES public.tables(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_checklist_items fk_rails_07ea1cc259; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_checklist_items
|
||||
ADD CONSTRAINT fk_rails_07ea1cc259 FOREIGN KEY (repository_id) REFERENCES public.repositories(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: assets fk_rails_0916329f9e; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -6018,14 +5979,6 @@ ALTER TABLE ONLY public.sample_types
|
|||
ADD CONSTRAINT fk_rails_316e1b5e2c FOREIGN KEY (created_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_list_items fk_rails_31e11a3b07; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_list_items
|
||||
ADD CONSTRAINT fk_rails_31e11a3b07 FOREIGN KEY (repository_id) REFERENCES public.repositories(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: oauth_access_grants fk_rails_330c32d8d9; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -7240,3 +7193,5 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20200204100934'),
|
||||
('20200326114643'),
|
||||
('20200331183640');
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue