Commit 44f55ba6 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'debian_distribution_components' into 'master'

Debian Group and Project Distribution Components

See merge request gitlab-org/gitlab!51732
parents 4d363af9 7ceecf83
# frozen_string_literal: true
module Packages
module Debian
module Component
extend ActiveSupport::Concern
included do
belongs_to :distribution, class_name: "Packages::Debian::#{container_type.capitalize}Distribution", inverse_of: :components
validates :distribution,
presence: true
validates :name,
presence: true,
length: { maximum: 255 },
uniqueness: { scope: %i[distribution_id] },
format: { with: Gitlab::Regex.debian_component_regex }
scope :with_distribution, ->(distribution) { where(distribution: distribution) }
scope :with_name, ->(name) { where(name: name) }
end
end
end
end
...@@ -18,6 +18,10 @@ module Packages ...@@ -18,6 +18,10 @@ module Packages
belongs_to container_type belongs_to container_type
belongs_to :creator, class_name: 'User' belongs_to :creator, class_name: 'User'
has_many :components,
class_name: "Packages::Debian::#{container_type.capitalize}Component",
foreign_key: :distribution_id,
inverse_of: :distribution
has_many :architectures, has_many :architectures,
class_name: "Packages::Debian::#{container_type.capitalize}Architecture", class_name: "Packages::Debian::#{container_type.capitalize}Architecture",
foreign_key: :distribution_id, foreign_key: :distribution_id,
......
# frozen_string_literal: true
class Packages::Debian::GroupComponent < ApplicationRecord
def self.container_type
:group
end
include Packages::Debian::Component
end
# frozen_string_literal: true
class Packages::Debian::ProjectComponent < ApplicationRecord
def self.container_type
:project
end
include Packages::Debian::Component
end
---
title: Debian Group and Project Distribution Components
merge_request: 51732
author: Mathieu Parent
type: added
# frozen_string_literal: true
class CreatePackagesDebianProjectComponents < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
UNIQUE_NAME = 'uniq_pkgs_deb_proj_components_on_distribution_id_and_name'
disable_ddl_transaction!
def up
unless table_exists?(:packages_debian_project_components)
create_table :packages_debian_project_components do |t|
t.timestamps_with_timezone
t.references :distribution,
foreign_key: { to_table: :packages_debian_project_distributions, on_delete: :cascade },
null: false,
index: false
t.text :name, null: false
t.index %w(distribution_id name),
name: UNIQUE_NAME,
unique: true,
using: :btree
end
end
add_text_limit :packages_debian_project_components, :name, 255
end
def down
drop_table :packages_debian_project_components
end
end
# frozen_string_literal: true
class CreatePackagesDebianGroupComponents < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
UNIQUE_NAME = 'uniq_pkgs_deb_grp_components_on_distribution_id_and_name'
disable_ddl_transaction!
def up
unless table_exists?(:packages_debian_group_components)
create_table :packages_debian_group_components do |t|
t.timestamps_with_timezone
t.references :distribution,
foreign_key: { to_table: :packages_debian_group_distributions, on_delete: :cascade },
null: false,
index: false
t.text :name, null: false
t.index %w(distribution_id name),
name: UNIQUE_NAME,
unique: true,
using: :btree
end
end
add_text_limit :packages_debian_group_components, :name, 255
end
def down
drop_table :packages_debian_group_components
end
end
2aad94b0577882df4fec3df3806993858dad9f4eb20db71c94f8590c6640d62e
\ No newline at end of file
e1265a293640d0d067672cb0426987c4a308025cf5a15b17bac8e30267dc8eaf
\ No newline at end of file
...@@ -14861,6 +14861,24 @@ CREATE SEQUENCE packages_debian_group_architectures_id_seq ...@@ -14861,6 +14861,24 @@ CREATE SEQUENCE packages_debian_group_architectures_id_seq
ALTER SEQUENCE packages_debian_group_architectures_id_seq OWNED BY packages_debian_group_architectures.id; ALTER SEQUENCE packages_debian_group_architectures_id_seq OWNED BY packages_debian_group_architectures.id;
CREATE TABLE packages_debian_group_components (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
distribution_id bigint NOT NULL,
name text NOT NULL,
CONSTRAINT check_a9bc7d85be CHECK ((char_length(name) <= 255))
);
CREATE SEQUENCE packages_debian_group_components_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE packages_debian_group_components_id_seq OWNED BY packages_debian_group_components.id;
CREATE TABLE packages_debian_group_distributions ( CREATE TABLE packages_debian_group_distributions (
id bigint NOT NULL, id bigint NOT NULL,
created_at timestamp with time zone NOT NULL, created_at timestamp with time zone NOT NULL,
...@@ -14920,6 +14938,24 @@ CREATE SEQUENCE packages_debian_project_architectures_id_seq ...@@ -14920,6 +14938,24 @@ CREATE SEQUENCE packages_debian_project_architectures_id_seq
ALTER SEQUENCE packages_debian_project_architectures_id_seq OWNED BY packages_debian_project_architectures.id; ALTER SEQUENCE packages_debian_project_architectures_id_seq OWNED BY packages_debian_project_architectures.id;
CREATE TABLE packages_debian_project_components (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
distribution_id bigint NOT NULL,
name text NOT NULL,
CONSTRAINT check_517559f298 CHECK ((char_length(name) <= 255))
);
CREATE SEQUENCE packages_debian_project_components_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE packages_debian_project_components_id_seq OWNED BY packages_debian_project_components.id;
CREATE TABLE packages_debian_project_distributions ( CREATE TABLE packages_debian_project_distributions (
id bigint NOT NULL, id bigint NOT NULL,
created_at timestamp with time zone NOT NULL, created_at timestamp with time zone NOT NULL,
...@@ -18917,10 +18953,14 @@ ALTER TABLE ONLY packages_conan_metadata ALTER COLUMN id SET DEFAULT nextval('pa ...@@ -18917,10 +18953,14 @@ ALTER TABLE ONLY packages_conan_metadata ALTER COLUMN id SET DEFAULT nextval('pa
ALTER TABLE ONLY packages_debian_group_architectures ALTER COLUMN id SET DEFAULT nextval('packages_debian_group_architectures_id_seq'::regclass); ALTER TABLE ONLY packages_debian_group_architectures ALTER COLUMN id SET DEFAULT nextval('packages_debian_group_architectures_id_seq'::regclass);
ALTER TABLE ONLY packages_debian_group_components ALTER COLUMN id SET DEFAULT nextval('packages_debian_group_components_id_seq'::regclass);
ALTER TABLE ONLY packages_debian_group_distributions ALTER COLUMN id SET DEFAULT nextval('packages_debian_group_distributions_id_seq'::regclass); ALTER TABLE ONLY packages_debian_group_distributions ALTER COLUMN id SET DEFAULT nextval('packages_debian_group_distributions_id_seq'::regclass);
ALTER TABLE ONLY packages_debian_project_architectures ALTER COLUMN id SET DEFAULT nextval('packages_debian_project_architectures_id_seq'::regclass); ALTER TABLE ONLY packages_debian_project_architectures ALTER COLUMN id SET DEFAULT nextval('packages_debian_project_architectures_id_seq'::regclass);
ALTER TABLE ONLY packages_debian_project_components ALTER COLUMN id SET DEFAULT nextval('packages_debian_project_components_id_seq'::regclass);
ALTER TABLE ONLY packages_debian_project_distributions ALTER COLUMN id SET DEFAULT nextval('packages_debian_project_distributions_id_seq'::regclass); ALTER TABLE ONLY packages_debian_project_distributions ALTER COLUMN id SET DEFAULT nextval('packages_debian_project_distributions_id_seq'::regclass);
ALTER TABLE ONLY packages_dependencies ALTER COLUMN id SET DEFAULT nextval('packages_dependencies_id_seq'::regclass); ALTER TABLE ONLY packages_dependencies ALTER COLUMN id SET DEFAULT nextval('packages_dependencies_id_seq'::regclass);
...@@ -20286,12 +20326,18 @@ ALTER TABLE ONLY packages_debian_file_metadata ...@@ -20286,12 +20326,18 @@ ALTER TABLE ONLY packages_debian_file_metadata
ALTER TABLE ONLY packages_debian_group_architectures ALTER TABLE ONLY packages_debian_group_architectures
ADD CONSTRAINT packages_debian_group_architectures_pkey PRIMARY KEY (id); ADD CONSTRAINT packages_debian_group_architectures_pkey PRIMARY KEY (id);
ALTER TABLE ONLY packages_debian_group_components
ADD CONSTRAINT packages_debian_group_components_pkey PRIMARY KEY (id);
ALTER TABLE ONLY packages_debian_group_distributions ALTER TABLE ONLY packages_debian_group_distributions
ADD CONSTRAINT packages_debian_group_distributions_pkey PRIMARY KEY (id); ADD CONSTRAINT packages_debian_group_distributions_pkey PRIMARY KEY (id);
ALTER TABLE ONLY packages_debian_project_architectures ALTER TABLE ONLY packages_debian_project_architectures
ADD CONSTRAINT packages_debian_project_architectures_pkey PRIMARY KEY (id); ADD CONSTRAINT packages_debian_project_architectures_pkey PRIMARY KEY (id);
ALTER TABLE ONLY packages_debian_project_components
ADD CONSTRAINT packages_debian_project_components_pkey PRIMARY KEY (id);
ALTER TABLE ONLY packages_debian_project_distributions ALTER TABLE ONLY packages_debian_project_distributions
ADD CONSTRAINT packages_debian_project_distributions_pkey PRIMARY KEY (id); ADD CONSTRAINT packages_debian_project_distributions_pkey PRIMARY KEY (id);
...@@ -23463,8 +23509,12 @@ CREATE INDEX tmp_index_on_vulnerabilities_non_dismissed ON vulnerabilities USING ...@@ -23463,8 +23509,12 @@ CREATE INDEX tmp_index_on_vulnerabilities_non_dismissed ON vulnerabilities USING
CREATE UNIQUE INDEX uniq_pkgs_deb_grp_architectures_on_distribution_id_and_name ON packages_debian_group_architectures USING btree (distribution_id, name); CREATE UNIQUE INDEX uniq_pkgs_deb_grp_architectures_on_distribution_id_and_name ON packages_debian_group_architectures USING btree (distribution_id, name);
CREATE UNIQUE INDEX uniq_pkgs_deb_grp_components_on_distribution_id_and_name ON packages_debian_group_components USING btree (distribution_id, name);
CREATE UNIQUE INDEX uniq_pkgs_deb_proj_architectures_on_distribution_id_and_name ON packages_debian_project_architectures USING btree (distribution_id, name); CREATE UNIQUE INDEX uniq_pkgs_deb_proj_architectures_on_distribution_id_and_name ON packages_debian_project_architectures USING btree (distribution_id, name);
CREATE UNIQUE INDEX uniq_pkgs_deb_proj_components_on_distribution_id_and_name ON packages_debian_project_components USING btree (distribution_id, name);
CREATE UNIQUE INDEX uniq_pkgs_debian_group_distributions_group_id_and_codename ON packages_debian_group_distributions USING btree (group_id, codename); CREATE UNIQUE INDEX uniq_pkgs_debian_group_distributions_group_id_and_codename ON packages_debian_group_distributions USING btree (group_id, codename);
CREATE UNIQUE INDEX uniq_pkgs_debian_group_distributions_group_id_and_suite ON packages_debian_group_distributions USING btree (group_id, suite); CREATE UNIQUE INDEX uniq_pkgs_debian_group_distributions_group_id_and_suite ON packages_debian_group_distributions USING btree (group_id, suite);
...@@ -25324,6 +25374,9 @@ ALTER TABLE ONLY users_ops_dashboard_projects ...@@ -25324,6 +25374,9 @@ ALTER TABLE ONLY users_ops_dashboard_projects
ALTER TABLE ONLY project_incident_management_settings ALTER TABLE ONLY project_incident_management_settings
ADD CONSTRAINT fk_rails_9c2ea1b7dd FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_9c2ea1b7dd FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY packages_debian_project_components
ADD CONSTRAINT fk_rails_9d072b5073 FOREIGN KEY (distribution_id) REFERENCES packages_debian_project_distributions(id) ON DELETE CASCADE;
ALTER TABLE ONLY gpg_keys ALTER TABLE ONLY gpg_keys
ADD CONSTRAINT fk_rails_9d1f5d8719 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_9d1f5d8719 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
...@@ -25786,6 +25839,9 @@ ALTER TABLE ONLY board_group_recent_visits ...@@ -25786,6 +25839,9 @@ ALTER TABLE ONLY board_group_recent_visits
ALTER TABLE ONLY resource_state_events ALTER TABLE ONLY resource_state_events
ADD CONSTRAINT fk_rails_f5827a7ccd FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL; ADD CONSTRAINT fk_rails_f5827a7ccd FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;
ALTER TABLE ONLY packages_debian_group_components
ADD CONSTRAINT fk_rails_f5f1ef54c6 FOREIGN KEY (distribution_id) REFERENCES packages_debian_group_distributions(id) ON DELETE CASCADE;
ALTER TABLE ONLY incident_management_oncall_shifts ALTER TABLE ONLY incident_management_oncall_shifts
ADD CONSTRAINT fk_rails_f6eef06841 FOREIGN KEY (participant_id) REFERENCES incident_management_oncall_participants(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_f6eef06841 FOREIGN KEY (participant_id) REFERENCES incident_management_oncall_participants(id) ON DELETE CASCADE;
......
# frozen_string_literal: true
FactoryBot.define do
factory :debian_group_component, class: 'Packages::Debian::GroupComponent' do
distribution { association(:debian_group_distribution) }
sequence(:name) { |n| "group-component-#{n}" }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :debian_project_component, class: 'Packages::Debian::ProjectComponent' do
distribution { association(:debian_project_distribution) }
sequence(:name) { |n| "project-component-#{n}" }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Debian::GroupComponent do
it_behaves_like 'Debian Distribution Component', :debian_group_component, :group, false
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Debian::ProjectComponent do
it_behaves_like 'Debian Distribution Component', :debian_project_component, :project, true
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.shared_examples 'Debian Distribution Component' do |factory, container, can_freeze|
let_it_be_with_refind(:component) { create(factory) } # rubocop:disable Rails/SaveBang
let_it_be(:component_same_distribution, freeze: can_freeze) { create(factory, distribution: component.distribution) }
let_it_be(:component_same_name, freeze: can_freeze) { create(factory, name: component.name) }
subject { component }
describe 'relationships' do
it { is_expected.to belong_to(:distribution).class_name("Packages::Debian::#{container.capitalize}Distribution").inverse_of(:components) }
end
describe 'validations' do
describe "#distribution" do
it { is_expected.to validate_presence_of(:distribution) }
end
describe '#name' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to allow_value('main').for(:name) }
it { is_expected.to allow_value('non-free').for(:name) }
it { is_expected.to allow_value('a' * 255).for(:name) }
it { is_expected.not_to allow_value('a' * 256).for(:name) }
it { is_expected.not_to allow_value('non/free').for(:name) }
it { is_expected.not_to allow_value('hé').for(:name) }
end
end
describe 'scopes' do
describe '.with_distribution' do
subject { described_class.with_distribution(component.distribution) }
it 'does not return other distributions' do
expect(subject.to_a).to eq([component, component_same_distribution])
end
end
describe '.with_name' do
subject { described_class.with_name(component.name) }
it 'does not return other distributions' do
expect(subject.to_a).to eq([component, component_same_name])
end
end
end
end
...@@ -17,6 +17,7 @@ RSpec.shared_examples 'Debian Distribution' do |factory, container, can_freeze| ...@@ -17,6 +17,7 @@ RSpec.shared_examples 'Debian Distribution' do |factory, container, can_freeze|
it { is_expected.to belong_to(container) } it { is_expected.to belong_to(container) }
it { is_expected.to belong_to(:creator).class_name('User') } it { is_expected.to belong_to(:creator).class_name('User') }
it { is_expected.to have_many(:components).class_name("Packages::Debian::#{container.capitalize}Component").inverse_of(:distribution) }
it { is_expected.to have_many(:architectures).class_name("Packages::Debian::#{container.capitalize}Architecture").inverse_of(:distribution) } it { is_expected.to have_many(:architectures).class_name("Packages::Debian::#{container.capitalize}Architecture").inverse_of(:distribution) }
end end
......
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