mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
Add restore columns to migrations
This commit is contained in:
parent
0cca53066f
commit
ebbce8d09e
5 changed files with 55 additions and 6 deletions
|
@ -3,6 +3,7 @@
|
|||
class RepositoryRow < ApplicationRecord
|
||||
include SearchableModel
|
||||
include SearchableByNameModel
|
||||
include ArchivableModel
|
||||
|
||||
belongs_to :repository, class_name: 'RepositoryBase'
|
||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||
|
@ -12,6 +13,11 @@ class RepositoryRow < ApplicationRecord
|
|||
class_name: 'User',
|
||||
inverse_of: :archived_repository_rows,
|
||||
optional: true
|
||||
belongs_to :restored_by,
|
||||
foreign_key: :archived_by_id,
|
||||
class_name: 'User',
|
||||
inverse_of: :restored_repository_rows,
|
||||
optional: true
|
||||
has_many :repository_cells, -> { order(:id) }, dependent: :destroy
|
||||
has_many :repository_columns, through: :repository_cells
|
||||
has_many :my_module_repository_rows,
|
||||
|
@ -23,10 +29,10 @@ 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
|
||||
# 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) }
|
||||
|
|
|
@ -207,6 +207,11 @@ class User < ApplicationRecord
|
|||
foreign_key: 'archived_by_id',
|
||||
inverse_of: :archived_by,
|
||||
dependent: :nullify
|
||||
has_many :restored_repository_rows,
|
||||
class_name: 'RepositoryRow',
|
||||
foreign_key: 'restored_by_id',
|
||||
inverse_of: :restored_by,
|
||||
dependent: :nullify
|
||||
has_many :assigned_my_module_repository_rows,
|
||||
class_name: 'MyModuleRepositoryRow',
|
||||
foreign_key: 'assigned_by_id'
|
||||
|
|
|
@ -5,7 +5,9 @@ class AddArchiveToRepository < ActiveRecord::Migration[6.0]
|
|||
change_table :repositories, bulk: true do |t|
|
||||
t.boolean :archived, default: false, null: false
|
||||
t.datetime :archived_on
|
||||
t.datetime :restored_on
|
||||
t.references :archived_by, index: true, foreign_key: { to_table: :users }
|
||||
t.references :restored_by, index: true, foreign_key: { to_table: :users }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,9 @@ class AddArchiveToRepositoryRow < ActiveRecord::Migration[6.0]
|
|||
change_table :repository_rows, bulk: true do |t|
|
||||
t.boolean :archived, default: false, null: false
|
||||
t.datetime :archived_on
|
||||
t.datetime :restored_on
|
||||
t.references :archived_by, index: true, foreign_key: { to_table: :users }
|
||||
t.references :restored_by, index: true, foreign_key: { to_table: :users }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1107,7 +1107,9 @@ CREATE TABLE public.repositories (
|
|||
my_module_id bigint,
|
||||
archived boolean DEFAULT false NOT NULL,
|
||||
archived_on timestamp without time zone,
|
||||
archived_by_id bigint
|
||||
restored_on timestamp without time zone,
|
||||
archived_by_id bigint,
|
||||
restored_by_id bigint
|
||||
);
|
||||
|
||||
|
||||
|
@ -1519,7 +1521,9 @@ CREATE TABLE public.repository_rows (
|
|||
parent_id bigint,
|
||||
archived boolean DEFAULT false NOT NULL,
|
||||
archived_on timestamp without time zone,
|
||||
archived_by_id bigint
|
||||
restored_on timestamp without time zone,
|
||||
archived_by_id bigint,
|
||||
restored_by_id bigint
|
||||
);
|
||||
|
||||
|
||||
|
@ -4798,6 +4802,13 @@ CREATE INDEX index_repositories_on_my_module_id ON public.repositories USING btr
|
|||
CREATE INDEX index_repositories_on_permission_level ON public.repositories USING btree (permission_level);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repositories_on_restored_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repositories_on_restored_by_id ON public.repositories USING btree (restored_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repositories_on_team_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -5029,6 +5040,13 @@ CREATE INDEX index_repository_rows_on_name ON public.repository_rows USING gin (
|
|||
CREATE INDEX index_repository_rows_on_repository_id ON public.repository_rows USING btree (repository_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_rows_on_restored_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_repository_rows_on_restored_by_id ON public.repository_rows USING btree (restored_by_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_repository_status_items_on_created_by_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -6449,6 +6467,14 @@ ALTER TABLE ONLY public.tables
|
|||
ADD CONSTRAINT fk_rails_943e1b03e5 FOREIGN KEY (created_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repositories fk_rails_94481f7751; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repositories
|
||||
ADD CONSTRAINT fk_rails_94481f7751 FOREIGN KEY (restored_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: steps fk_rails_954ff833e4; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -6937,6 +6963,14 @@ ALTER TABLE ONLY public.repository_text_values
|
|||
ADD CONSTRAINT fk_rails_e4c61d807b FOREIGN KEY (created_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: repository_rows fk_rails_e7c4398649; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.repository_rows
|
||||
ADD CONSTRAINT fk_rails_e7c4398649 FOREIGN KEY (restored_by_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: samples fk_rails_ea3d01785c; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
|
Loading…
Reference in a new issue