Commit 9c4fb2ce authored by Igor Drozdov's avatar Igor Drozdov

Introduce required_code_owners_sections table

It's required to implement section based approval rules
parent 8a5e9d54
---
title: Introduce required_code_owners_sections table
merge_request: 43573
author:
type: added
# frozen_string_literal: true
class CreateRequiredCodeOwnersSections < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
with_lock_retries do
create_table :required_code_owners_sections, if_not_exists: true do |t|
t.references :protected_branch, null: false, foreign_key: { on_delete: :cascade }
t.text :name, null: false
end
end
add_text_limit :required_code_owners_sections, :name, 1024
end
def down
with_lock_retries do
drop_table :required_code_owners_sections, if_exists: true
end
end
end
106757b0f30d3c89fcafa13be92271090fa107831fd538ee087d7ce212842492
\ No newline at end of file
......@@ -15448,6 +15448,22 @@ CREATE TABLE repository_languages (
share double precision NOT NULL
);
CREATE TABLE required_code_owners_sections (
id bigint NOT NULL,
protected_branch_id bigint NOT NULL,
name text NOT NULL,
CONSTRAINT check_e58d53741e CHECK ((char_length(name) <= 1024))
);
CREATE SEQUENCE required_code_owners_sections_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE required_code_owners_sections_id_seq OWNED BY required_code_owners_sections.id;
CREATE TABLE requirements (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
......@@ -17746,6 +17762,8 @@ ALTER TABLE ONLY releases ALTER COLUMN id SET DEFAULT nextval('releases_id_seq':
ALTER TABLE ONLY remote_mirrors ALTER COLUMN id SET DEFAULT nextval('remote_mirrors_id_seq'::regclass);
ALTER TABLE ONLY required_code_owners_sections ALTER COLUMN id SET DEFAULT nextval('required_code_owners_sections_id_seq'::regclass);
ALTER TABLE ONLY requirements ALTER COLUMN id SET DEFAULT nextval('requirements_id_seq'::regclass);
ALTER TABLE ONLY requirements_management_test_reports ALTER COLUMN id SET DEFAULT nextval('requirements_management_test_reports_id_seq'::regclass);
......@@ -19027,6 +19045,9 @@ ALTER TABLE ONLY releases
ALTER TABLE ONLY remote_mirrors
ADD CONSTRAINT remote_mirrors_pkey PRIMARY KEY (id);
ALTER TABLE ONLY required_code_owners_sections
ADD CONSTRAINT required_code_owners_sections_pkey PRIMARY KEY (id);
ALTER TABLE ONLY requirements_management_test_reports
ADD CONSTRAINT requirements_management_test_reports_pkey PRIMARY KEY (id);
......@@ -21202,6 +21223,8 @@ CREATE INDEX index_remote_mirrors_on_project_id ON remote_mirrors USING btree (p
CREATE UNIQUE INDEX index_repository_languages_on_project_and_languages_id ON repository_languages USING btree (project_id, programming_language_id);
CREATE INDEX index_required_code_owners_sections_on_protected_branch_id ON required_code_owners_sections USING btree (protected_branch_id);
CREATE INDEX index_requirements_management_test_reports_on_author_id ON requirements_management_test_reports USING btree (author_id);
CREATE INDEX index_requirements_management_test_reports_on_build_id ON requirements_management_test_reports USING btree (build_id);
......@@ -23299,6 +23322,9 @@ ALTER TABLE ONLY clusters_kubernetes_namespaces
ALTER TABLE ONLY approval_merge_request_rules_users
ADD CONSTRAINT fk_rails_80e6801803 FOREIGN KEY (approval_merge_request_rule_id) REFERENCES approval_merge_request_rules(id) ON DELETE CASCADE;
ALTER TABLE ONLY required_code_owners_sections
ADD CONSTRAINT fk_rails_817708cf2d FOREIGN KEY (protected_branch_id) REFERENCES protected_branches(id) ON DELETE CASCADE;
ALTER TABLE ONLY dast_site_profiles
ADD CONSTRAINT fk_rails_83e309d69e FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
......
......@@ -7,6 +7,8 @@ module EE
prepended do
has_and_belongs_to_many :approval_project_rules
has_many :required_code_owners_sections, class_name: "ProtectedBranch::RequiredCodeOwnersSection"
protected_ref_access_levels :unprotect
end
......
# frozen_string_literal: true
class ProtectedBranch::RequiredCodeOwnersSection < ApplicationRecord
self.table_name = 'required_code_owners_sections'
belongs_to :protected_branch
end
......@@ -8,6 +8,10 @@ RSpec.describe ProtectedBranch do
let(:project) { subject.project }
let(:user) { create(:user) }
describe 'associations' do
it { is_expected.to have_many(:required_code_owners_sections).class_name('ProtectedBranch::RequiredCodeOwnersSection') }
end
shared_examples 'uniqueness validation' do |access_level_class|
let(:factory_name) { access_level_class.to_s.underscore.sub('/', '_').to_sym }
let(:association_name) { access_level_class.to_s.underscore.sub('protected_branch/', '').pluralize.to_sym }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedBranch::RequiredCodeOwnersSection do
describe 'associations' do
it { is_expected.to belong_to(:protected_branch) }
end
end
......@@ -304,6 +304,7 @@ protected_branches:
- push_access_levels
- unprotect_access_levels
- approval_project_rules
- required_code_owners_sections
protected_tags:
- project
- create_access_levels
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment