Skip to content

Add user setting for "Home Organization"

Abdul Wadood requested to merge 428668-add-user-home-organization-setting into master

What does this MR do and why?

This is part of the Organization entity being developed by grouptenant scale. Read more about it here https://docs.gitlab.com/ee/architecture/blueprints/organization/.

Here we add a column to store the home organization of the user.

The users can be members of multiple organizations but can choose one of their organization to be their home organization which will be used as a landing page when the user logs in and when viewing the user profile to provide information about this user.

Migration output

up
bin/rails db:migrate
WARNING: This version of GitLab depends on gitlab-shell 14.31.0, but you're running 14.30.1. Please update gitlab-shell.
main: == [advisory_lock_connection] object_id: 184300, pg_backend_pid: 53469
main: == 20231115081652 AddHomeOrganizationIdToUserPreferences: migrating ===========
main: -- add_column(:user_preferences, :home_organization_id, :bigint, {:null=>true})
main:    -> 0.0018s
main: == 20231115081652 AddHomeOrganizationIdToUserPreferences: migrated (0.0060s) ==

main: == [advisory_lock_connection] object_id: 184300, pg_backend_pid: 53469
ci: == [advisory_lock_connection] object_id: 184600, pg_backend_pid: 53471
ci: == 20231115081652 AddHomeOrganizationIdToUserPreferences: migrating ===========
ci: -- add_column(:user_preferences, :home_organization_id, :bigint, {:null=>true})
ci:    -> 0.0011s
ci: == 20231115081652 AddHomeOrganizationIdToUserPreferences: migrated (0.0133s) ==

ci: == [advisory_lock_connection] object_id: 184600, pg_backend_pid: 53471
main: == [advisory_lock_connection] object_id: 184800, pg_backend_pid: 53474
main: == 20231122072428 AddHomeOrganizationIdIndexToUserPreferences: migrating ======
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.1250s
main: -- index_exists?(:user_preferences, :home_organization_id, {:name=>"index_user_preferences_on_home_organization_id", :algorithm=>:concurrently})
main:    -> 0.0036s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0004s
main: -- add_index(:user_preferences, :home_organization_id, {:name=>"index_user_preferences_on_home_organization_id", :algorithm=>:concurrently})
main:    -> 0.0027s
main: -- execute("RESET statement_timeout")
main:    -> 0.0003s
main: == 20231122072428 AddHomeOrganizationIdIndexToUserPreferences: migrated (0.1501s)

main: == [advisory_lock_connection] object_id: 184800, pg_backend_pid: 53474
ci: == [advisory_lock_connection] object_id: 184940, pg_backend_pid: 53476
ci: == 20231122072428 AddHomeOrganizationIdIndexToUserPreferences: migrating ======
ci: -- transaction_open?(nil)
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0007s
ci: -- index_exists?(:user_preferences, :home_organization_id, {:name=>"index_user_preferences_on_home_organization_id", :algorithm=>:concurrently})
ci:    -> 0.0032s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0005s
ci: -- add_index(:user_preferences, :home_organization_id, {:name=>"index_user_preferences_on_home_organization_id", :algorithm=>:concurrently})
ci:    -> 0.0030s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0005s
ci: == 20231122072428 AddHomeOrganizationIdIndexToUserPreferences: migrated (0.0278s)

ci: == [advisory_lock_connection] object_id: 184940, pg_backend_pid: 53476
main: == [advisory_lock_connection] object_id: 185200, pg_backend_pid: 53479
main: == 20231201095326 AddHomeOrganizationIdFkToUserPreferences: migrating =========
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("ALTER TABLE user_preferences ADD CONSTRAINT fk_e5e029c10b FOREIGN KEY (home_organization_id) REFERENCES organizations (id) ON DELETE SET NULL NOT VALID;")
main:    -> 0.0018s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- execute("ALTER TABLE user_preferences VALIDATE CONSTRAINT fk_e5e029c10b;")
main:    -> 0.0010s
main: -- execute("RESET statement_timeout")
main:    -> 0.0003s
main: == 20231201095326 AddHomeOrganizationIdFkToUserPreferences: migrated (0.0239s)

main: == [advisory_lock_connection] object_id: 185200, pg_backend_pid: 53479
ci: == [advisory_lock_connection] object_id: 185460, pg_backend_pid: 53481
ci: == 20231201095326 AddHomeOrganizationIdFkToUserPreferences: migrating =========
ci: -- transaction_open?(nil)
ci:    -> 0.0000s
ci: -- transaction_open?(nil)
ci:    -> 0.0000s
ci: -- execute("ALTER TABLE user_preferences ADD CONSTRAINT fk_e5e029c10b FOREIGN KEY (home_organization_id) REFERENCES organizations (id) ON DELETE SET NULL NOT VALID;")
ci:    -> 0.0020s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0002s
ci: -- execute("ALTER TABLE user_preferences VALIDATE CONSTRAINT fk_e5e029c10b;")
ci:    -> 0.0030s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0003s
ci: == 20231201095326 AddHomeOrganizationIdFkToUserPreferences: migrated (0.0295s)

ci: == [advisory_lock_connection] object_id: 185460, pg_backend_pid: 53481
down
for v in 20231201095326 20231122072428 20231115081652; do bin/rails db:migrate:down:ci VERSION=$v && bin/rails db:migrate:down:main VERSION=$v; done
WARNING: This version of GitLab depends on gitlab-shell 14.31.0, but you're running 14.30.1. Please update gitlab-shell.
ci: == [advisory_lock_connection] object_id: 183940, pg_backend_pid: 56580
ci: == 20231201095326 AddHomeOrganizationIdFkToUserPreferences: reverting =========
ci: -- transaction_open?(nil)
ci:    -> 0.0000s
ci: -- remove_foreign_key(:user_preferences, {:column=>:home_organization_id})
ci:    -> 0.0026s
ci: == 20231201095326 AddHomeOrganizationIdFkToUserPreferences: reverted (0.1254s)

ci: == [advisory_lock_connection] object_id: 183940, pg_backend_pid: 56580
WARNING: This version of GitLab depends on gitlab-shell 14.31.0, but you're running 14.30.1. Please update gitlab-shell.
main: == [advisory_lock_connection] object_id: 183940, pg_backend_pid: 57023
main: == 20231201095326 AddHomeOrganizationIdFkToUserPreferences: reverting =========
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- remove_foreign_key(:user_preferences, {:column=>:home_organization_id})
main:    -> 0.0031s
main: == 20231201095326 AddHomeOrganizationIdFkToUserPreferences: reverted (0.2130s)

main: == [advisory_lock_connection] object_id: 183940, pg_backend_pid: 57023
WARNING: This version of GitLab depends on gitlab-shell 14.31.0, but you're running 14.30.1. Please update gitlab-shell.
ci: == [advisory_lock_connection] object_id: 183940, pg_backend_pid: 57453
ci: == 20231122072428 AddHomeOrganizationIdIndexToUserPreferences: reverting ======
ci: -- transaction_open?(nil)
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.1276s
ci: -- indexes(:user_preferences)
ci:    -> 0.0029s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0003s
ci: -- remove_index(:user_preferences, {:algorithm=>:concurrently, :name=>"index_user_preferences_on_home_organization_id"})
ci:    -> 0.0013s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0002s
ci: == 20231122072428 AddHomeOrganizationIdIndexToUserPreferences: reverted (0.1520s)

ci: == [advisory_lock_connection] object_id: 183940, pg_backend_pid: 57453
WARNING: This version of GitLab depends on gitlab-shell 14.31.0, but you're running 14.30.1. Please update gitlab-shell.
main: == [advisory_lock_connection] object_id: 183920, pg_backend_pid: 57860
main: == 20231122072428 AddHomeOrganizationIdIndexToUserPreferences: reverting ======
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0999s
main: -- indexes(:user_preferences)
main:    -> 0.0027s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- remove_index(:user_preferences, {:algorithm=>:concurrently, :name=>"index_user_preferences_on_home_organization_id"})
main:    -> 0.0020s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20231122072428 AddHomeOrganizationIdIndexToUserPreferences: reverted (0.1167s)

main: == [advisory_lock_connection] object_id: 183920, pg_backend_pid: 57860
WARNING: This version of GitLab depends on gitlab-shell 14.31.0, but you're running 14.30.1. Please update gitlab-shell.
ci: == [advisory_lock_connection] object_id: 182980, pg_backend_pid: 58260
ci: == 20231115081652 AddHomeOrganizationIdToUserPreferences: reverting ===========
ci: -- remove_column(:user_preferences, :home_organization_id, :bigint, {:null=>true})
ci:    -> 0.0013s
ci: == 20231115081652 AddHomeOrganizationIdToUserPreferences: reverted (0.0116s) ==

ci: == [advisory_lock_connection] object_id: 182980, pg_backend_pid: 58260
WARNING: This version of GitLab depends on gitlab-shell 14.31.0, but you're running 14.30.1. Please update gitlab-shell.
main: == [advisory_lock_connection] object_id: 183900, pg_backend_pid: 58673
main: == 20231115081652 AddHomeOrganizationIdToUserPreferences: reverting ===========
main: -- remove_column(:user_preferences, :home_organization_id, :bigint, {:null=>true})
main:    -> 0.0015s
main: == 20231115081652 AddHomeOrganizationIdToUserPreferences: reverted (0.0064s) ==

main: == [advisory_lock_connection] object_id: 183900, pg_backend_pid: 58673

Screenshots or screen recordings

The frontend was already developed. See !134796 (merged)

How to set up and validate locally

It can be tested after #429999 (closed).

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #428668 (closed)

Edited by Abdul Wadood

Merge request reports

Loading