Commit 8b5b39ce authored by Tiger Watson's avatar Tiger Watson

Merge branch '349573-add-namespace_id-column-to-members-table' into 'master'

Add member_namespace_id column to members table

See merge request gitlab-org/gitlab!77592
parents a130811f aae6e5f1
......@@ -27,6 +27,7 @@ class Member < ApplicationRecord
belongs_to :created_by, class_name: "User"
belongs_to :user
belongs_to :source, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
belongs_to :member_namespace, inverse_of: :namespace_members, foreign_key: 'member_namespace_id', class_name: 'Namespace'
has_one :member_task
delegate :name, :username, :email, :last_activity_on, to: :user, prefix: true
......
......@@ -44,6 +44,7 @@ class Namespace < ApplicationRecord
has_many :project_statistics
has_one :namespace_settings, inverse_of: :namespace, class_name: 'NamespaceSetting', autosave: true
has_one :namespace_route, foreign_key: :namespace_id, autosave: false, inverse_of: :namespace, class_name: 'Route'
has_many :namespace_members, foreign_key: :member_namespace_id, inverse_of: :member_namespace, class_name: 'Member'
has_many :runner_namespaces, inverse_of: :namespace, class_name: 'Ci::RunnerNamespace'
has_many :runners, through: :runner_namespaces, source: :runner, class_name: 'Ci::Runner'
......
# frozen_string_literal: true
class AddMemberNamespaceReference < Gitlab::Database::Migration[1.0]
enable_lock_retries!
def up
add_column :members, :member_namespace_id, :bigint unless column_exists?(:members, :member_namespace_id)
end
def down
remove_column :members, :member_namespace_id if column_exists?(:members, :member_namespace_id)
end
end
# frozen_string_literal: true
class AddMemberNamespaceIndex < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
INDEX_NAME = 'index_members_on_member_namespace_id'
def up
add_concurrent_index :members, :member_namespace_id, unique: false, name: INDEX_NAME
add_concurrent_foreign_key :members, :namespaces, column: :member_namespace_id, on_delete: :nullify, reverse_lock_order: true
end
def down
with_lock_retries do
remove_foreign_key_if_exists :members, column: :member_namespace_id
end
remove_concurrent_index_by_name :members, INDEX_NAME
end
end
775ac42ad194bd0175a6925e1c2e83c11d57a8d4430ad08a70e3d5275ca2e709
\ No newline at end of file
4813b55e933564851f2fec9a2fa5900409eff226fec34ae0be1895307f603904
\ No newline at end of file
......@@ -15979,7 +15979,8 @@ CREATE TABLE members (
ldap boolean DEFAULT false NOT NULL,
override boolean DEFAULT false NOT NULL,
state smallint DEFAULT 0,
invite_email_success boolean DEFAULT true NOT NULL
invite_email_success boolean DEFAULT true NOT NULL,
member_namespace_id bigint
);
CREATE SEQUENCE members_id_seq
......@@ -26567,6 +26568,8 @@ CREATE INDEX index_members_on_invite_email ON members USING btree (invite_email)
CREATE UNIQUE INDEX index_members_on_invite_token ON members USING btree (invite_token);
CREATE INDEX index_members_on_member_namespace_id ON members USING btree (member_namespace_id);
CREATE INDEX index_members_on_requested_at ON members USING btree (requested_at);
CREATE INDEX index_members_on_source_id_and_source_type ON members USING btree (source_id, source_type);
......@@ -29586,6 +29589,9 @@ ALTER TABLE ONLY epics
ALTER TABLE ONLY dast_profiles
ADD CONSTRAINT fk_aa76ef30e9 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY members
ADD CONSTRAINT fk_aa82dcc1c6 FOREIGN KEY (member_namespace_id) REFERENCES namespaces(id) ON DELETE SET NULL;
ALTER TABLE ONLY alert_management_alerts
ADD CONSTRAINT fk_aad61aedca FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE SET NULL;
......@@ -904,6 +904,7 @@ excluded_attributes:
- :release_id
project_members:
- :source_id
- :member_namespace_id
- :invite_email_success
- :state
group_members:
......
......@@ -136,6 +136,7 @@ project_members:
- source
- project
- member_task
- member_namespace
merge_requests:
- status_check_responses
- subscriptions
......
......@@ -9,6 +9,7 @@ RSpec.describe Member do
describe 'Associations' do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:member_namespace) }
it { is_expected.to have_one(:member_task) }
end
......
......@@ -29,6 +29,7 @@ RSpec.describe Namespace do
it { is_expected.to have_one :admin_note }
it { is_expected.to have_many :pending_builds }
it { is_expected.to have_one :namespace_route }
it { is_expected.to have_many :namespace_members }
describe '#children' do
let_it_be(:group) { create(:group) }
......
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