Add archive to repository

This commit is contained in:
Mojca Lorber 2020-06-04 15:44:47 +02:00
parent e32d942aec
commit d3806e53a5
3 changed files with 22 additions and 0 deletions

View file

@ -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|

View file

@ -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'

View 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