From 2ab9069d338799f496787c441f811293c43a1901 Mon Sep 17 00:00:00 2001 From: Allison Browne Date: Tue, 27 Sep 2022 12:01:03 -0400 Subject: [PATCH 1/2] Add migration for direction column of ci scope * Add a migration to add the direction column to the ci_job_token_project_scope_links * Use smallint for enum column * Default to 0 or outbound direction Changelog: added --- app/models/ci/job_token/project_scope_link.rb | 5 +++++ ..._add_inbound_ci_job_token_project_scope_links.rb | 13 +++++++++++++ db/schema_migrations/20220922143612 | 1 + db/structure.sql | 3 ++- spec/models/ci/job_token/project_scope_link_spec.rb | 6 ++++++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20220922143612_add_inbound_ci_job_token_project_scope_links.rb create mode 100644 db/schema_migrations/20220922143612 diff --git a/app/models/ci/job_token/project_scope_link.rb b/app/models/ci/job_token/project_scope_link.rb index c2ab8ca0929716..3fdf07123e6cfb 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 00000000000000..2e6653723dce9c --- /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 + 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 00000000000000..4f93a218c746d0 --- /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 d6665c0999dc03..52b8d5968e6493 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 ); 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 c000a3e29f7527..4c1f11130a41da 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) } -- GitLab From f90a70280bbdaf6a37e24783e4cf26eedd206e82 Mon Sep 17 00:00:00 2001 From: Allison Browne Date: Thu, 29 Sep 2022 10:52:11 -0400 Subject: [PATCH 2/2] Add null false to ci_job_token_project_scope_links --- ...220922143612_add_inbound_ci_job_token_project_scope_links.rb | 2 +- db/structure.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index 2e6653723dce9c..50b43ee4db8c5b 100644 --- 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 @@ -4,7 +4,7 @@ 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 + add_column :ci_job_token_project_scope_links, :direction, :integer, limit: 2, default: 0, null: false end def down diff --git a/db/structure.sql b/db/structure.sql index 52b8d5968e6493..0524290374bd06 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -12833,7 +12833,7 @@ CREATE TABLE ci_job_token_project_scope_links ( target_project_id bigint NOT NULL, added_by_id bigint, created_at timestamp with time zone NOT NULL, - direction smallint DEFAULT 0 + direction smallint DEFAULT 0 NOT NULL ); CREATE SEQUENCE ci_job_token_project_scope_links_id_seq -- GitLab