Commit 0fc3359e authored by Mathieu Parent's avatar Mathieu Parent

Debian Group and Project Distribution Architectures

See 2.4.5 of https://gitlab.com/gitlab-org/gitlab/-/issues/5835#note_414103286
parent a2610ef0
# frozen_string_literal: true
module Packages
module Debian
module Architecture
extend ActiveSupport::Concern
included do
belongs_to :distribution, class_name: "Packages::Debian::#{container_type.capitalize}Distribution", inverse_of: :architectures
validates :distribution,
presence: true
validates :name,
presence: true,
length: { maximum: 255 },
uniqueness: { scope: %i[distribution_id] },
format: { with: Gitlab::Regex.debian_architecture_regex }
scope :with_distribution, ->(distribution) { where(distribution: distribution) }
scope :with_name, ->(name) { where(name: name) }
end
end
end
end
......@@ -18,6 +18,11 @@ module Packages
belongs_to container_type
belongs_to :creator, class_name: 'User'
has_many :architectures,
class_name: "Packages::Debian::#{container_type.capitalize}Architecture",
foreign_key: :distribution_id,
inverse_of: :distribution
validates :codename,
presence: true,
uniqueness: { scope: [container_foreign_key] },
......
# frozen_string_literal: true
class Packages::Debian::GroupArchitecture < ApplicationRecord
def self.container_type
:group
end
include Packages::Debian::Architecture
end
# frozen_string_literal: true
class Packages::Debian::ProjectArchitecture < ApplicationRecord
def self.container_type
:project
end
include Packages::Debian::Architecture
end
---
title: Debian Group and Project Distribution Architectures
merge_request: 51265
author: Mathieu Parent
type: added
# frozen_string_literal: true
class CreatePackagesDebianProjectArchitectures < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'idx_pkgs_deb_proj_architectures_on_distribution_id'
UNIQUE_NAME = 'uniq_pkgs_deb_proj_architectures_on_distribution_id_and_name'
disable_ddl_transaction!
def up
with_lock_retries do
unless table_exists?(:packages_debian_project_architectures)
create_table :packages_debian_project_architectures do |t|
t.timestamps_with_timezone
t.references :distribution,
foreign_key: { to_table: :packages_debian_project_distributions, on_delete: :cascade },
null: false,
index: { name: INDEX_NAME }
t.text :name, null: false
t.index %w(distribution_id name),
name: UNIQUE_NAME,
unique: true,
using: :btree
end
end
end
add_text_limit :packages_debian_project_architectures, :name, 255
end
def down
drop_table :packages_debian_project_architectures
end
end
# frozen_string_literal: true
class CreatePackagesDebianGroupArchitectures < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'idx_pkgs_deb_grp_architectures_on_distribution_id'
UNIQUE_NAME = 'uniq_pkgs_deb_grp_architectures_on_distribution_id_and_name'
disable_ddl_transaction!
def up
with_lock_retries do
unless table_exists?(:packages_debian_group_architectures)
create_table :packages_debian_group_architectures do |t|
t.timestamps_with_timezone
t.references :distribution,
foreign_key: { to_table: :packages_debian_group_distributions, on_delete: :cascade },
null: false,
index: { name: INDEX_NAME }
t.text :name, null: false
t.index %w(distribution_id name),
name: UNIQUE_NAME,
unique: true,
using: :btree
end
end
end
add_text_limit :packages_debian_group_architectures, :name, 255
end
def down
drop_table :packages_debian_group_architectures
end
end
e9ca7eb8a47f6c48667135eca26f729471f8bb4ffa91dfceea87d98c8f2a616b
\ No newline at end of file
b613f8654641948b2933910ebbfc926fd801b18c00a5d23b1c801a9ba9925520
\ No newline at end of file
......@@ -14765,6 +14765,24 @@ CREATE TABLE packages_debian_file_metadata (
CONSTRAINT check_e6e1fffcca CHECK ((char_length(architecture) <= 255))
);
CREATE TABLE packages_debian_group_architectures (
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_ddb220164a CHECK ((char_length(name) <= 255))
);
CREATE SEQUENCE packages_debian_group_architectures_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE packages_debian_group_architectures_id_seq OWNED BY packages_debian_group_architectures.id;
CREATE TABLE packages_debian_group_distributions (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
......@@ -14806,6 +14824,24 @@ CREATE SEQUENCE packages_debian_group_distributions_id_seq
ALTER SEQUENCE packages_debian_group_distributions_id_seq OWNED BY packages_debian_group_distributions.id;
CREATE TABLE packages_debian_project_architectures (
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_9c2e1c99d8 CHECK ((char_length(name) <= 255))
);
CREATE SEQUENCE packages_debian_project_architectures_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE packages_debian_project_architectures_id_seq OWNED BY packages_debian_project_architectures.id;
CREATE TABLE packages_debian_project_distributions (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
......@@ -18785,8 +18821,12 @@ ALTER TABLE ONLY packages_conan_file_metadata ALTER COLUMN id SET DEFAULT nextva
ALTER TABLE ONLY packages_conan_metadata ALTER COLUMN id SET DEFAULT nextval('packages_conan_metadata_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_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_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);
......@@ -20143,9 +20183,15 @@ ALTER TABLE ONLY packages_conan_metadata
ALTER TABLE ONLY packages_debian_file_metadata
ADD CONSTRAINT packages_debian_file_metadata_pkey PRIMARY KEY (package_file_id);
ALTER TABLE ONLY packages_debian_group_architectures
ADD CONSTRAINT packages_debian_group_architectures_pkey PRIMARY KEY (id);
ALTER TABLE ONLY packages_debian_group_distributions
ADD CONSTRAINT packages_debian_group_distributions_pkey PRIMARY KEY (id);
ALTER TABLE ONLY packages_debian_project_architectures
ADD CONSTRAINT packages_debian_project_architectures_pkey PRIMARY KEY (id);
ALTER TABLE ONLY packages_debian_project_distributions
ADD CONSTRAINT packages_debian_project_distributions_pkey PRIMARY KEY (id);
......@@ -20863,6 +20909,10 @@ CREATE INDEX idx_packages_build_infos_on_package_id ON packages_build_infos USIN
CREATE INDEX idx_packages_packages_on_project_id_name_version_package_type ON packages_packages USING btree (project_id, name, version, package_type);
CREATE INDEX idx_pkgs_deb_grp_architectures_on_distribution_id ON packages_debian_group_architectures USING btree (distribution_id);
CREATE INDEX idx_pkgs_deb_proj_architectures_on_distribution_id ON packages_debian_project_architectures USING btree (distribution_id);
CREATE UNIQUE INDEX idx_pkgs_dep_links_on_pkg_id_dependency_id_dependency_type ON packages_dependency_links USING btree (package_id, dependency_id, dependency_type);
CREATE INDEX idx_proj_feat_usg_on_jira_dvcs_cloud_last_sync_at_and_proj_id ON project_feature_usages USING btree (jira_dvcs_cloud_last_sync_at, project_id) WHERE (jira_dvcs_cloud_last_sync_at IS NOT NULL);
......@@ -23299,6 +23349,10 @@ CREATE INDEX tmp_index_oauth_applications_on_id_where_trusted ON oauth_applicati
CREATE INDEX tmp_index_on_vulnerabilities_non_dismissed ON vulnerabilities USING btree (id) WHERE (state <> 2);
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_proj_architectures_on_distribution_id_and_name ON packages_debian_project_architectures 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_suite ON packages_debian_group_distributions USING btree (group_id, suite);
......@@ -24771,6 +24825,9 @@ ALTER TABLE ONLY issue_user_mentions
ALTER TABLE ONLY merge_request_assignees
ADD CONSTRAINT fk_rails_579d375628 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY packages_debian_project_architectures
ADD CONSTRAINT fk_rails_5808663adf FOREIGN KEY (distribution_id) REFERENCES packages_debian_project_distributions(id) ON DELETE CASCADE;
ALTER TABLE ONLY clusters_applications_cilium
ADD CONSTRAINT fk_rails_59dc12eea6 FOREIGN KEY (cluster_id) REFERENCES clusters(id) ON DELETE CASCADE;
......@@ -25557,6 +25614,9 @@ ALTER TABLE ONLY experiment_subjects
ALTER TABLE ONLY ci_daily_build_group_report_results
ADD CONSTRAINT fk_rails_ee072d13b3 FOREIGN KEY (last_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE;
ALTER TABLE ONLY packages_debian_group_architectures
ADD CONSTRAINT fk_rails_ef667d1b03 FOREIGN KEY (distribution_id) REFERENCES packages_debian_group_distributions(id) ON DELETE CASCADE;
ALTER TABLE ONLY label_priorities
ADD CONSTRAINT fk_rails_ef916d14fa FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
......
# frozen_string_literal: true
FactoryBot.define do
factory :debian_group_architecture, class: 'Packages::Debian::GroupArchitecture' do
distribution { association(:debian_group_distribution) }
sequence(:name) { |n| "group-arch-#{n}" }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :debian_project_architecture, class: 'Packages::Debian::ProjectArchitecture' do
distribution { association(:debian_project_distribution) }
sequence(:name) { |n| "project-arch-#{n}" }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Debian::GroupArchitecture do
it_behaves_like 'Debian Distribution Architecture', :debian_group_architecture, :group, false
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Debian::ProjectArchitecture do
it_behaves_like 'Debian Distribution Architecture', :debian_project_architecture, :project, true
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.shared_examples 'Debian Distribution Architecture' do |factory, container, can_freeze|
let_it_be_with_refind(:architecture) { create(factory) } # rubocop:disable Rails/SaveBang
let_it_be(:architecture_same_distribution, freeze: can_freeze) { create(factory, distribution: architecture.distribution) }
let_it_be(:architecture_same_name, freeze: can_freeze) { create(factory, name: architecture.name) }
subject { architecture }
describe 'relationships' do
it { is_expected.to belong_to(:distribution).class_name("Packages::Debian::#{container.capitalize}Distribution").inverse_of(:architectures) }
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('amd64').for(:name) }
it { is_expected.to allow_value('kfreebsd-i386').for(:name) }
it { is_expected.not_to allow_value('-a').for(:name) }
it { is_expected.not_to allow_value('AMD64').for(:name) }
end
end
describe 'scopes' do
describe '.with_distribution' do
subject { described_class.with_distribution(architecture.distribution) }
it 'does not return other distributions' do
expect(subject.to_a).to eq([architecture, architecture_same_distribution])
end
end
describe '.with_name' do
subject { described_class.with_name(architecture.name) }
it 'does not return other distributions' do
expect(subject.to_a).to eq([architecture, architecture_same_name])
end
end
end
end
......@@ -15,6 +15,8 @@ RSpec.shared_examples 'Debian Distribution' do |factory, container, can_freeze|
describe 'relationships' do
it { is_expected.to belong_to(container) }
it { is_expected.to belong_to(:creator).class_name('User') }
it { is_expected.to have_many(:architectures).class_name("Packages::Debian::#{container.capitalize}Architecture").inverse_of(:distribution) }
end
describe 'validations' do
......
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