diff --git a/app/models/ci/job_token/project_scope_link.rb b/app/models/ci/job_token/project_scope_link.rb index c2ab8ca09297163447823a7b5bf8b4071ff9f1a5..3fdf07123e6cfb4c6696773567ef48b32c8a3f86 100644 --- a/app/models/ci/job_token/project_scope_link.rb +++ b/app/models/ci/job_token/project_scope_link.rb @@ -19,6 +19,11 @@ class ProjectScopeLink < Ci::ApplicationRecord validates :target_project, presence: true validate :not_self_referential_link + enum direction: { + outbound: 0, + inbound: 1 + } + def self.for_source_and_target(source_project, target_project) self.find_by(source_project: source_project, target_project: target_project) end diff --git a/db/migrate/20220922143612_add_inbound_ci_job_token_project_scope_links.rb b/db/migrate/20220922143612_add_inbound_ci_job_token_project_scope_links.rb new file mode 100644 index 0000000000000000000000000000000000000000..50b43ee4db8c5b9d48de811eae83fd06c9acab99 --- /dev/null +++ b/db/migrate/20220922143612_add_inbound_ci_job_token_project_scope_links.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddInboundCiJobTokenProjectScopeLinks < Gitlab::Database::Migration[2.0] + enable_lock_retries! + + def up + add_column :ci_job_token_project_scope_links, :direction, :integer, limit: 2, default: 0, null: false + end + + def down + remove_column :ci_job_token_project_scope_links, :direction + end +end diff --git a/db/schema_migrations/20220922143612 b/db/schema_migrations/20220922143612 new file mode 100644 index 0000000000000000000000000000000000000000..4f93a218c746d04523193e65eca34dc706e3fef6 --- /dev/null +++ b/db/schema_migrations/20220922143612 @@ -0,0 +1 @@ +4685b471f00f8ef5e8d8e521c50dc276c757c9f9caa50b1aa20c1f98b8b008c5 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index d6665c0999dc03a16cc996c1d6b17368f4b53d68..0524290374bd06e598166ddb42cb02edbfd10f5e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -12832,7 +12832,8 @@ CREATE TABLE ci_job_token_project_scope_links ( source_project_id bigint NOT NULL, target_project_id bigint NOT NULL, added_by_id bigint, - created_at timestamp with time zone NOT NULL + created_at timestamp with time zone NOT NULL, + direction smallint DEFAULT 0 NOT NULL ); CREATE SEQUENCE ci_job_token_project_scope_links_id_seq diff --git a/spec/models/ci/job_token/project_scope_link_spec.rb b/spec/models/ci/job_token/project_scope_link_spec.rb index c000a3e29f752785921ff96a3615b7cf6f460e0c..4c1f11130a41da0228ff3fa8b85436d95b1edc32 100644 --- a/spec/models/ci/job_token/project_scope_link_spec.rb +++ b/spec/models/ci/job_token/project_scope_link_spec.rb @@ -89,6 +89,12 @@ end end + describe 'enums' do + let(:directions) { { outbound: 0, inbound: 1 } } + + it { is_expected.to define_enum_for(:direction).with_values(directions) } + end + context 'loose foreign key on ci_job_token_project_scope_links.source_project_id' do it_behaves_like 'cleanup by a loose foreign key' do let!(:parent) { create(:project) }