Commit 8bde5395 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '215160-create-group-deploy_keys' into 'master'

Add group_deploy_keys table

Closes #215160

See merge request gitlab-org/gitlab!30886
parents b3ceabdd 00831200
# frozen_string_literal: true
class GroupDeployKey < Key
self.table_name = 'group_deploy_keys'
validates :user, presence: true
def type
'DeployKey'
end
end
# frozen_string_literal: true
class CreateGroupDeployKeys < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
unless table_exists?(:group_deploy_keys)
with_lock_retries do
create_table :group_deploy_keys do |t|
t.references :user, foreign_key: { on_delete: :restrict }, index: true
t.timestamps_with_timezone
t.datetime_with_timezone :last_used_at
t.datetime_with_timezone :expires_at
t.text :key, null: false, unique: true
t.text :title
t.text :fingerprint, null: false, unique: true
t.binary :fingerprint_sha256
t.index :fingerprint, unique: true
t.index :fingerprint_sha256
end
end
end
add_text_limit(:group_deploy_keys, :key, 4096)
add_text_limit(:group_deploy_keys, :title, 255)
add_text_limit(:group_deploy_keys, :fingerprint, 255)
end
def down
drop_table :group_deploy_keys
end
end
......@@ -3181,6 +3181,31 @@ CREATE TABLE public.group_deletion_schedules (
marked_for_deletion_on date NOT NULL
);
CREATE TABLE public.group_deploy_keys (
id bigint NOT NULL,
user_id bigint,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
last_used_at timestamp with time zone,
expires_at timestamp with time zone,
key text NOT NULL,
title text,
fingerprint text NOT NULL,
fingerprint_sha256 bytea,
CONSTRAINT check_cc0365908d CHECK ((char_length(title) <= 255)),
CONSTRAINT check_e4526dcf91 CHECK ((char_length(fingerprint) <= 255)),
CONSTRAINT check_f58fa0a0f7 CHECK ((char_length(key) <= 4096))
);
CREATE SEQUENCE public.group_deploy_keys_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.group_deploy_keys_id_seq OWNED BY public.group_deploy_keys.id;
CREATE TABLE public.group_deploy_tokens (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
......@@ -7689,6 +7714,8 @@ ALTER TABLE ONLY public.grafana_integrations ALTER COLUMN id SET DEFAULT nextval
ALTER TABLE ONLY public.group_custom_attributes ALTER COLUMN id SET DEFAULT nextval('public.group_custom_attributes_id_seq'::regclass);
ALTER TABLE ONLY public.group_deploy_keys ALTER COLUMN id SET DEFAULT nextval('public.group_deploy_keys_id_seq'::regclass);
ALTER TABLE ONLY public.group_deploy_tokens ALTER COLUMN id SET DEFAULT nextval('public.group_deploy_tokens_id_seq'::regclass);
ALTER TABLE ONLY public.group_group_links ALTER COLUMN id SET DEFAULT nextval('public.group_group_links_id_seq'::regclass);
......@@ -8497,6 +8524,9 @@ ALTER TABLE ONLY public.group_custom_attributes
ALTER TABLE ONLY public.group_deletion_schedules
ADD CONSTRAINT group_deletion_schedules_pkey PRIMARY KEY (group_id);
ALTER TABLE ONLY public.group_deploy_keys
ADD CONSTRAINT group_deploy_keys_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.group_deploy_tokens
ADD CONSTRAINT group_deploy_tokens_pkey PRIMARY KEY (id);
......@@ -9953,6 +9983,12 @@ CREATE INDEX index_group_deletion_schedules_on_marked_for_deletion_on ON public.
CREATE INDEX index_group_deletion_schedules_on_user_id ON public.group_deletion_schedules USING btree (user_id);
CREATE UNIQUE INDEX index_group_deploy_keys_on_fingerprint ON public.group_deploy_keys USING btree (fingerprint);
CREATE INDEX index_group_deploy_keys_on_fingerprint_sha256 ON public.group_deploy_keys USING btree (fingerprint_sha256);
CREATE INDEX index_group_deploy_keys_on_user_id ON public.group_deploy_keys USING btree (user_id);
CREATE INDEX index_group_deploy_tokens_on_deploy_token_id ON public.group_deploy_tokens USING btree (deploy_token_id);
CREATE UNIQUE INDEX index_group_deploy_tokens_on_group_and_deploy_token_ids ON public.group_deploy_tokens USING btree (group_id, deploy_token_id);
......@@ -12177,6 +12213,9 @@ ALTER TABLE ONLY public.clusters_applications_knative
ALTER TABLE ONLY public.terraform_states
ADD CONSTRAINT fk_rails_558901b030 FOREIGN KEY (locked_by_user_id) REFERENCES public.users(id);
ALTER TABLE ONLY public.group_deploy_keys
ADD CONSTRAINT fk_rails_5682fc07f8 FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE RESTRICT;
ALTER TABLE ONLY public.issue_user_mentions
ADD CONSTRAINT fk_rails_57581fda73 FOREIGN KEY (issue_id) REFERENCES public.issues(id) ON DELETE CASCADE;
......@@ -13831,6 +13870,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200429182245
20200430103158
20200430130048
20200430174637
20200505164958
20200505171834
20200505172405
......
......@@ -13,6 +13,10 @@ FactoryBot.define do
factory :deploy_key, class: 'DeployKey'
factory :group_deploy_key, class: 'GroupDeployKey' do
user
end
factory :personal_key do
user
end
......
# frozen_string_literal: true
require 'spec_helper'
describe GroupDeployKey do
it { is_expected.to validate_presence_of(:user) }
it 'is of type DeployKey' do
expect(build(:group_deploy_key).type).to eq('DeployKey')
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