Commit e35cc79a authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'fj-create-group-repository-storage-move-table' into 'master'

Create Groups::RepositoryStorageMove class

See merge request gitlab-org/gitlab!51803
parents 7eee28b8 e30304b5
---
title: Create Groups::RepositoryStorageMove table
merge_request: 51803
author:
type: added
# frozen_string_literal: true
class CreateGroupRepositoryStorageMove < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
unless table_exists?(:group_repository_storage_moves)
with_lock_retries do
create_table :group_repository_storage_moves do |t|
t.timestamps_with_timezone
t.references :group, references: :namespace, column: :group_id, index: true, null: false
t.integer :state, limit: 2, default: 1, null: false
t.text :source_storage_name, null: false
t.text :destination_storage_name, null: false
t.foreign_key :namespaces, column: :group_id, on_delete: :cascade
end
end
end
add_text_limit(:group_repository_storage_moves, :source_storage_name, 255, constraint_name: 'group_repository_storage_moves_source_storage_name')
add_text_limit(:group_repository_storage_moves, :destination_storage_name, 255, constraint_name: 'group_repository_storage_moves_destination_storage_name')
end
def down
with_lock_retries do
drop_table :group_repository_storage_moves
end
end
end
5415850ae27c507fd8b1df20951e25b42352f4f9ec8e1402019533170edabdb8
\ No newline at end of file
......@@ -13044,6 +13044,27 @@ CREATE TABLE group_merge_request_approval_settings (
allow_author_approval boolean DEFAULT false NOT NULL
);
CREATE TABLE group_repository_storage_moves (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
group_id bigint NOT NULL,
state smallint DEFAULT 1 NOT NULL,
source_storage_name text NOT NULL,
destination_storage_name text NOT NULL,
CONSTRAINT group_repository_storage_moves_destination_storage_name CHECK ((char_length(destination_storage_name) <= 255)),
CONSTRAINT group_repository_storage_moves_source_storage_name CHECK ((char_length(source_storage_name) <= 255))
);
CREATE SEQUENCE group_repository_storage_moves_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE group_repository_storage_moves_id_seq OWNED BY group_repository_storage_moves.id;
CREATE TABLE group_wiki_repositories (
shard_id bigint NOT NULL,
group_id bigint NOT NULL,
......@@ -18733,6 +18754,8 @@ ALTER TABLE ONLY group_group_links ALTER COLUMN id SET DEFAULT nextval('group_gr
ALTER TABLE ONLY group_import_states ALTER COLUMN group_id SET DEFAULT nextval('group_import_states_group_id_seq'::regclass);
ALTER TABLE ONLY group_repository_storage_moves ALTER COLUMN id SET DEFAULT nextval('group_repository_storage_moves_id_seq'::regclass);
ALTER TABLE ONLY historical_data ALTER COLUMN id SET DEFAULT nextval('historical_data_id_seq'::regclass);
ALTER TABLE ONLY identities ALTER COLUMN id SET DEFAULT nextval('identities_id_seq'::regclass);
......@@ -19969,6 +19992,9 @@ ALTER TABLE ONLY group_import_states
ALTER TABLE ONLY group_merge_request_approval_settings
ADD CONSTRAINT group_merge_request_approval_settings_pkey PRIMARY KEY (group_id);
ALTER TABLE ONLY group_repository_storage_moves
ADD CONSTRAINT group_repository_storage_moves_pkey PRIMARY KEY (id);
ALTER TABLE ONLY group_wiki_repositories
ADD CONSTRAINT group_wiki_repositories_pkey PRIMARY KEY (group_id);
......@@ -21950,6 +21976,8 @@ CREATE INDEX index_group_import_states_on_group_id ON group_import_states USING
CREATE INDEX index_group_import_states_on_user_id ON group_import_states USING btree (user_id) WHERE (user_id IS NOT NULL);
CREATE INDEX index_group_repository_storage_moves_on_group_id ON group_repository_storage_moves USING btree (group_id);
CREATE UNIQUE INDEX index_group_stages_on_group_id_group_value_stream_id_and_name ON analytics_cycle_analytics_group_stages USING btree (group_id, group_value_stream_id, name);
CREATE UNIQUE INDEX index_group_wiki_repositories_on_disk_path ON group_wiki_repositories USING btree (disk_path);
......@@ -25260,6 +25288,9 @@ ALTER TABLE ONLY packages_pypi_metadata
ALTER TABLE ONLY packages_dependency_links
ADD CONSTRAINT fk_rails_96ef1c00d3 FOREIGN KEY (package_id) REFERENCES packages_packages(id) ON DELETE CASCADE;
ALTER TABLE ONLY group_repository_storage_moves
ADD CONSTRAINT fk_rails_982bb5daf1 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY resource_label_events
ADD CONSTRAINT fk_rails_9851a00031 FOREIGN KEY (merge_request_id) REFERENCES merge_requests(id) ON DELETE CASCADE;
......
......@@ -51,6 +51,7 @@ module EE
delegate :enforced_group_managed_accounts?, :enforced_sso?, to: :saml_provider, allow_nil: true
has_one :group_wiki_repository
has_many :repository_storage_moves, class_name: 'Groups::RepositoryStorageMove', inverse_of: :container
belongs_to :file_template_project, class_name: "Project"
......
# frozen_string_literal: true
# Groups::RepositoryStorageMove store details of repository storage moves for a
# group. For example, moving a group to another gitaly node to help
# balance storage capacity.
module Groups
class RepositoryStorageMove < ApplicationRecord
self.table_name = 'group_repository_storage_moves'
belongs_to :container, class_name: 'Group', inverse_of: :repository_storage_moves, foreign_key: :group_id
alias_attribute :group, :container
scope :with_groups, -> { includes(container: :route) }
end
end
......@@ -27,6 +27,7 @@ RSpec.describe Group do
it { is_expected.to have_many(:provisioned_user_details).inverse_of(:provisioned_by_group) }
it { is_expected.to have_many(:provisioned_users) }
it { is_expected.to have_one(:group_merge_request_approval_setting) }
it { is_expected.to have_many(:repository_storage_moves) }
it_behaves_like 'model with wiki' do
let(:container) { create(:group, :nested, :wiki_repo) }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::RepositoryStorageMove, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:container).class_name('Group') }
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