Commit 3ca9ae5b authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'sav-1566-pat-for-projects-db-changes' into 'master'

Add project access token table

See merge request gitlab-org/gitlab!33272
parents f246b39e e395ea7d
---
title: Add ProjectAccessToken table
merge_request: 33272
author:
type: added
# frozen_string_literal: true
class CreateProjectAccessTokens < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
create_table :project_access_tokens, primary_key: [:personal_access_token_id, :project_id] do |t|
t.column :personal_access_token_id, :bigint, null: false
t.column :project_id, :bigint, null: false
end
add_index :project_access_tokens, :project_id
end
end
# frozen_string_literal: true
class AddProjectsForeignKeyToProjectAccessTokens < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_foreign_key :project_access_tokens, :projects, column: :project_id
end
def down
remove_foreign_key_if_exists :project_access_tokens, column: :project_id
end
end
# frozen_string_literal: true
class AddPersonalAccessTokenForeignKeyToProjectAccessTokens < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_foreign_key :project_access_tokens, :personal_access_tokens, column: :personal_access_token_id
end
def down
remove_foreign_key_if_exists :project_access_tokens, column: :personal_access_token_id
end
end
......@@ -5041,6 +5041,11 @@ CREATE SEQUENCE public.programming_languages_id_seq
ALTER SEQUENCE public.programming_languages_id_seq OWNED BY public.programming_languages.id;
CREATE TABLE public.project_access_tokens (
personal_access_token_id bigint NOT NULL,
project_id bigint NOT NULL
);
CREATE TABLE public.project_alerting_settings (
project_id integer NOT NULL,
encrypted_token character varying NOT NULL,
......@@ -8790,6 +8795,9 @@ ALTER TABLE ONLY public.pool_repositories
ALTER TABLE ONLY public.programming_languages
ADD CONSTRAINT programming_languages_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.project_access_tokens
ADD CONSTRAINT project_access_tokens_pkey PRIMARY KEY (personal_access_token_id, project_id);
ALTER TABLE ONLY public.project_alerting_settings
ADD CONSTRAINT project_alerting_settings_pkey PRIMARY KEY (project_id);
......@@ -9159,8 +9167,6 @@ CREATE UNIQUE INDEX design_management_designs_versions_uniqueness ON public.desi
CREATE INDEX design_user_mentions_on_design_id_and_note_id_index ON public.design_user_mentions USING btree (design_id, note_id);
CREATE INDEX dev_index_route_on_path_trigram ON public.routes USING gin (path public.gin_trgm_ops);
CREATE UNIQUE INDEX epic_user_mentions_on_epic_id_and_note_id_index ON public.epic_user_mentions USING btree (epic_id, note_id);
CREATE UNIQUE INDEX epic_user_mentions_on_epic_id_index ON public.epic_user_mentions USING btree (epic_id) WHERE (note_id IS NULL);
......@@ -10505,6 +10511,8 @@ CREATE UNIQUE INDEX index_pool_repositories_on_source_project_id_and_shard_id ON
CREATE UNIQUE INDEX index_programming_languages_on_name ON public.programming_languages USING btree (name);
CREATE INDEX index_project_access_tokens_on_project_id ON public.project_access_tokens USING btree (project_id);
CREATE UNIQUE INDEX index_project_aliases_on_name ON public.project_aliases USING btree (name);
CREATE INDEX index_project_aliases_on_project_id ON public.project_aliases USING btree (project_id);
......@@ -11426,6 +11434,9 @@ ALTER TABLE ONLY public.deploy_keys_projects
ALTER TABLE ONLY public.issue_assignees
ADD CONSTRAINT fk_5e0c8d9154 FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.project_access_tokens
ADD CONSTRAINT fk_5f7e8450e1 FOREIGN KEY (personal_access_token_id) REFERENCES public.personal_access_tokens(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.merge_requests
ADD CONSTRAINT fk_6149611a04 FOREIGN KEY (assignee_id) REFERENCES public.users(id) ON DELETE SET NULL;
......@@ -11636,6 +11647,9 @@ ALTER TABLE ONLY public.fork_network_members
ALTER TABLE ONLY public.vulnerabilities
ADD CONSTRAINT fk_b1de915a15 FOREIGN KEY (author_id) REFERENCES public.users(id) ON DELETE SET NULL;
ALTER TABLE ONLY public.project_access_tokens
ADD CONSTRAINT fk_b27801bfbf FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.protected_tag_create_access_levels
ADD CONSTRAINT fk_b4eb82fe3c FOREIGN KEY (group_id) REFERENCES public.namespaces(id) ON DELETE CASCADE;
......@@ -13871,6 +13885,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200429181955
20200429182245
20200430103158
20200430123614
20200430130048
20200430174637
20200505164958
......@@ -13975,5 +13990,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200609142508
20200609212701
20200615083635
20200615121217
20200615123055
\.
......@@ -92,7 +92,8 @@ RSpec.describe 'Database schema' do
let(:indexes) { connection.indexes(table) }
let(:columns) { connection.columns(table) }
let(:foreign_keys) { connection.foreign_keys(table) }
let(:primary_key_column) { connection.primary_key(table) }
# take the first column in case we're using a composite primary key
let(:primary_key_column) { Array(connection.primary_key(table)).first }
context 'all foreign keys' do
# for index to be effective, the FK constraint has to be at first place
......
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