Commit d40a4e5a authored by Steve Abrams's avatar Steve Abrams

Add models for dependency proxy ttl policies

Migration and model updates introducing the
dependency_proxy_image_ttl_group_policies
table and its associated model updates.

Changelog: other
parent cfc84394
# frozen_string_literal: true
class DependencyProxy::ImageTtlGroupPolicy < ApplicationRecord
self.primary_key = :group_id
belongs_to :group
validates :group, presence: true
validates :enabled, inclusion: { in: [true, false] }
validates :ttl, numericality: { greater_than: 0 }, allow_nil: true
end
......@@ -74,6 +74,7 @@ class Group < Namespace
has_many :oauth_applications, class_name: 'Doorkeeper::Application', as: :owner, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_one :dependency_proxy_setting, class_name: 'DependencyProxy::GroupSetting'
has_one :dependency_proxy_image_ttl_policy, class_name: 'DependencyProxy::ImageTtlGroupPolicy'
has_many :dependency_proxy_blobs, class_name: 'DependencyProxy::Blob'
has_many :dependency_proxy_manifests, class_name: 'DependencyProxy::Manifest'
......
# frozen_string_literal: true
class CreateDependencyProxyImageTtlGroupPolicies < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
def up
with_lock_retries do
create_table :dependency_proxy_image_ttl_group_policies, id: false do |t|
t.timestamps_with_timezone null: false
t.references :group, primary_key: true, default: nil, index: false, foreign_key: { to_table: :namespaces, on_delete: :cascade }
t.integer :ttl, default: 90
t.boolean :enabled, null: false, default: false
end
end
end
def down
with_lock_retries do
drop_table :dependency_proxy_image_ttl_group_policies
end
end
end
62496310640493bf9b7f0e1cbe91b170542da3250a1cf482f5e0237d0e8847b1
\ No newline at end of file
......@@ -12395,6 +12395,14 @@ CREATE SEQUENCE dependency_proxy_group_settings_id_seq
ALTER SEQUENCE dependency_proxy_group_settings_id_seq OWNED BY dependency_proxy_group_settings.id;
CREATE TABLE dependency_proxy_image_ttl_group_policies (
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
group_id bigint NOT NULL,
ttl integer DEFAULT 90,
enabled boolean DEFAULT false NOT NULL
);
CREATE TABLE dependency_proxy_manifests (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
......@@ -21722,6 +21730,9 @@ ALTER TABLE ONLY dependency_proxy_blobs
ALTER TABLE ONLY dependency_proxy_group_settings
ADD CONSTRAINT dependency_proxy_group_settings_pkey PRIMARY KEY (id);
ALTER TABLE ONLY dependency_proxy_image_ttl_group_policies
ADD CONSTRAINT dependency_proxy_image_ttl_group_policies_pkey PRIMARY KEY (group_id);
ALTER TABLE ONLY dependency_proxy_manifests
ADD CONSTRAINT dependency_proxy_manifests_pkey PRIMARY KEY (id);
......@@ -27360,6 +27371,9 @@ ALTER TABLE ONLY reviews
ALTER TABLE ONLY draft_notes
ADD CONSTRAINT fk_rails_2a8dac9901 FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY dependency_proxy_image_ttl_group_policies
ADD CONSTRAINT fk_rails_2b1896d021 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY group_group_links
ADD CONSTRAINT fk_rails_2b2353ca49 FOREIGN KEY (shared_with_group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe DependencyProxy::ImageTtlGroupPolicy, type: :model do
describe 'relationships' do
it { is_expected.to belong_to(:group) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:group) }
describe '#enabled' do
it { is_expected.to allow_value(true).for(:enabled) }
it { is_expected.to allow_value(false).for(:enabled) }
it { is_expected.not_to allow_value(nil).for(:enabled) }
end
describe '#ttl' do
it { is_expected.to validate_numericality_of(:ttl).allow_nil.is_greater_than(0) }
end
end
end
......@@ -30,6 +30,7 @@ RSpec.describe Group do
it { is_expected.to have_many(:group_deploy_keys) }
it { is_expected.to have_many(:integrations) }
it { is_expected.to have_one(:dependency_proxy_setting) }
it { is_expected.to have_one(:dependency_proxy_image_ttl_policy) }
it { is_expected.to have_many(:dependency_proxy_blobs) }
it { is_expected.to have_many(:dependency_proxy_manifests) }
it { is_expected.to have_many(:debian_distributions).class_name('Packages::Debian::GroupDistribution').dependent(:destroy) }
......
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