Commit 4dae8709 authored by Brett Walker's avatar Brett Walker

Add member_namespace_id to members table

in support of upcoming work on members table

Changelog: changed
parent 829106c0
...@@ -27,6 +27,8 @@ class Member < ApplicationRecord ...@@ -27,6 +27,8 @@ class Member < ApplicationRecord
belongs_to :created_by, class_name: "User" belongs_to :created_by, class_name: "User"
belongs_to :user belongs_to :user
belongs_to :source, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations 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'
belongs_to :namespace, inverse_of: :namespace_route
has_one :member_task has_one :member_task
delegate :name, :username, :email, :last_activity_on, to: :user, prefix: true delegate :name, :username, :email, :last_activity_on, to: :user, prefix: true
......
...@@ -44,6 +44,7 @@ class Namespace < ApplicationRecord ...@@ -44,6 +44,7 @@ class Namespace < ApplicationRecord
has_many :project_statistics has_many :project_statistics
has_one :namespace_settings, inverse_of: :namespace, class_name: 'NamespaceSetting', autosave: true 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_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 :runner_namespaces, inverse_of: :namespace, class_name: 'Ci::RunnerNamespace'
has_many :runners, through: :runner_namespaces, source: :runner, class_name: 'Ci::Runner' 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
...@@ -15956,7 +15956,8 @@ CREATE TABLE members ( ...@@ -15956,7 +15956,8 @@ CREATE TABLE members (
ldap boolean DEFAULT false NOT NULL, ldap boolean DEFAULT false NOT NULL,
override boolean DEFAULT false NOT NULL, override boolean DEFAULT false NOT NULL,
state smallint DEFAULT 0, 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 CREATE SEQUENCE members_id_seq
...@@ -26537,6 +26538,8 @@ CREATE INDEX index_members_on_invite_email ON members USING btree (invite_email) ...@@ -26537,6 +26538,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 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_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); CREATE INDEX index_members_on_source_id_and_source_type ON members USING btree (source_id, source_type);
...@@ -29554,6 +29557,9 @@ ALTER TABLE ONLY epics ...@@ -29554,6 +29557,9 @@ ALTER TABLE ONLY epics
ALTER TABLE ONLY dast_profiles ALTER TABLE ONLY dast_profiles
ADD CONSTRAINT fk_aa76ef30e9 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; 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 ALTER TABLE ONLY alert_management_alerts
ADD CONSTRAINT fk_aad61aedca FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE SET NULL; ADD CONSTRAINT fk_aad61aedca FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE SET NULL;
...@@ -9,6 +9,7 @@ RSpec.describe Member do ...@@ -9,6 +9,7 @@ RSpec.describe Member do
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:member_namespace) }
it { is_expected.to have_one(:member_task) } it { is_expected.to have_one(:member_task) }
end end
......
...@@ -29,6 +29,7 @@ RSpec.describe Namespace do ...@@ -29,6 +29,7 @@ RSpec.describe Namespace do
it { is_expected.to have_one :admin_note } it { is_expected.to have_one :admin_note }
it { is_expected.to have_many :pending_builds } it { is_expected.to have_many :pending_builds }
it { is_expected.to have_one :namespace_route } it { is_expected.to have_one :namespace_route }
it { is_expected.to have_many :namespace_members }
describe '#children' do describe '#children' do
let_it_be(:group) { create(:group) } 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