mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Add archive to repository
This commit is contained in:
parent
e32d942aec
commit
d3806e53a5
3 changed files with 22 additions and 0 deletions
|
@ -9,6 +9,7 @@ class RepositoryBase < ApplicationRecord
|
|||
|
||||
belongs_to :team
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
belongs_to :archived_by, foreign_key: :archived_by_id, class_name: 'User', inverse_of: :repository, optional: true
|
||||
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
|
||||
|
@ -17,10 +18,17 @@ class RepositoryBase < ApplicationRecord
|
|||
auto_strip_attributes :name, nullify: false
|
||||
validates :team, presence: true
|
||||
validates :created_by, presence: true
|
||||
with_options if: :archived do
|
||||
validates :archived_by, presence: true
|
||||
validates :archived_on, presence: true
|
||||
end
|
||||
|
||||
# Not discarded
|
||||
default_scope -> { kept }
|
||||
|
||||
scope :active, -> { where(archived: false) }
|
||||
scope :archived, -> { where(archived: true) }
|
||||
|
||||
def cell_preload_includes
|
||||
cell_includes = []
|
||||
repository_columns.pluck(:data_type).each do |data_type|
|
||||
|
|
|
@ -197,6 +197,9 @@ class User < ApplicationRecord
|
|||
class_name: 'Protocol',
|
||||
foreign_key: 'restored_by_id',
|
||||
inverse_of: :restored_by
|
||||
has_many :archived_repositories,
|
||||
class_name: 'RepositoryBase',
|
||||
foreign_key: 'archived_by_id'
|
||||
has_many :assigned_my_module_repository_rows,
|
||||
class_name: 'MyModuleRepositoryRow',
|
||||
foreign_key: 'assigned_by_id'
|
||||
|
|
11
db/migrate/20200603125407_add_archive_to_repository.rb
Normal file
11
db/migrate/20200603125407_add_archive_to_repository.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddArchiveToRepository < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_table :repositories, bulk: true do |t|
|
||||
t.boolean :archived, default: false, null: false
|
||||
t.datetime :archived_on
|
||||
t.references :archived_by, index: true, foreign_key: { to_table: :users }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue