mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 23:25:31 +08:00
Add archive to repository rows
This commit is contained in:
parent
a29a8d67f4
commit
42d6d727b9
4 changed files with 43 additions and 2 deletions
|
@ -7,6 +7,7 @@ class RepositoryRow < ApplicationRecord
|
|||
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'
|
||||
belongs_to :archived_by, foreign_key: :archived_by_id, class_name: 'User', inverse_of: :repository_row, optional: true
|
||||
has_many :repository_cells, -> { order(:id) }, dependent: :destroy
|
||||
has_many :repository_columns, through: :repository_cells
|
||||
has_many :my_module_repository_rows,
|
||||
|
@ -18,6 +19,13 @@ class RepositoryRow < ApplicationRecord
|
|||
presence: true,
|
||||
length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||
validates :created_by, presence: true
|
||||
with_options if: :archived do
|
||||
validates :archived_by, presence: true
|
||||
validates :archived_on, presence: true
|
||||
end
|
||||
|
||||
scope :active, -> { where(archived: false) }
|
||||
scope :archived, -> { where(archived: true) }
|
||||
|
||||
def self.viewable_by_user(user, teams)
|
||||
where(repository: Repository.viewable_by_user(user, teams))
|
||||
|
|
|
@ -200,6 +200,9 @@ class User < ApplicationRecord
|
|||
has_many :archived_repositories,
|
||||
class_name: 'RepositoryBase',
|
||||
foreign_key: 'archived_by_id'
|
||||
has_many :archived_repository_rows,
|
||||
class_name: 'RepositoryRow',
|
||||
foreign_key: 'archived_by_id'
|
||||
has_many :assigned_my_module_repository_rows,
|
||||
class_name: 'MyModuleRepositoryRow',
|
||||
foreign_key: 'assigned_by_id'
|
||||
|
|
11
db/migrate/20200604210943_add_archive_to_repository_row.rb
Normal file
11
db/migrate/20200604210943_add_archive_to_repository_row.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddArchiveToRepositoryRow < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_table :repository_rows, 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
|
|
@ -1516,7 +1516,10 @@ CREATE TABLE public.repository_rows (
|
|||
name character varying,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
parent_id bigint
|
||||
parent_id bigint,
|
||||
archived boolean DEFAULT false NOT NULL,
|
||||
archived_on timestamp without time zone,
|
||||
archived_by_id bigint
|
||||
);
|
||||
|
||||
|
||||
|
@ -4998,6 +5001,13 @@ CREATE INDEX index_repository_number_values_on_data_text ON public.repository_nu
|
|||
CREATE INDEX index_repository_number_values_on_last_modified_by_id ON public.repository_number_values USING btree (last_modified_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_rows_on_archived_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_rows_on_archived_by_id ON public.repository_rows USING btree (archived_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_rows_on_id_text; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -6159,6 +6169,14 @@ ALTER TABLE ONLY public.projects
|
|||
ADD CONSTRAINT fk_rails_6b025b17ca FOREIGN KEY (archived_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_rows fk_rails_6b4114fff4; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_rows
|
||||
ADD CONSTRAINT fk_rails_6b4114fff4 FOREIGN KEY (archived_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: sample_my_modules fk_rails_6c0db0045d; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -7213,6 +7231,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20200204100934'),
|
||||
('20200326114643'),
|
||||
('20200331183640'),
|
||||
('20200603125407');
|
||||
('20200603125407'),
|
||||
('20200604210943');
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue