Skip to content

Add path attribute to organizations

Manoj M J requested to merge 410428-add-path-attribute-to-organization into master

What does this MR do and why?

For #410428 (closed) - we need to set up a path attribute on the organizations table.

This MR (in order):

Migrations:

  • adds path attribute to organizations table, with null: false and a DEFAULT of ''
  • adds a UNIQUE index on organizations.path
  • adds a limit of 255 to organizations.path

Post deploy migrations:

  • fixes paths of existing records (we only have 1 record, and there is no UI or API currently for users to be able to create more records on this table on the organizations table currently), such that organizations.path is set to lower(organizations.name)
  • removes the DEFAULT of '' from organizations.path

Migrations

UP migration
main: == [advisory_lock_connection] object_id: 279080, pg_backend_pid: 66102
main: == 20230530112122 AddPathToOrganizations: migrating ===========================
main: -- add_column(:organizations, :path, :text, {:null=>false, :default=>""})
main:    -> 0.0033s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.1113s
main: -- index_exists?(:organizations, :path, {:name=>"unique_organizations_on_path", :unique=>true, :algorithm=>:concurrently})
main:    -> 0.0012s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- add_index(:organizations, :path, {:name=>"unique_organizations_on_path", :unique=>true, :algorithm=>:concurrently})
main:    -> 0.0021s
main: -- execute("RESET statement_timeout")
main:    -> 0.0004s
main: == 20230530112122 AddPathToOrganizations: migrated (0.1316s) ==================

main: == 20230530112602 AddTextLimitOnOrganizationPath: migrating ===================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- execute("ALTER TABLE organizations\nADD CONSTRAINT check_0b4296b5ea\nCHECK ( char_length(path) <= 255 )\nNOT VALID;\n")
main:    -> 0.0011s
main: -- execute("ALTER TABLE organizations VALIDATE CONSTRAINT check_0b4296b5ea;")
main:    -> 0.0005s
main: == 20230530112602 AddTextLimitOnOrganizationPath: migrated (0.0170s) ==========

main: == 20230530114845 CleanupOrganizationsWithNullPath: migrating =================
main: == 20230530114845 CleanupOrganizationsWithNullPath: migrated (0.0345s) ========

main: == 20230530115830 RemoveDefaultOnOrganizationPath: migrating ==================
main: -- change_column_default(:organizations, :path, nil)
main:    -> 0.0057s
main: == 20230530115830 RemoveDefaultOnOrganizationPath: migrated (0.0239s) =========

main: == [advisory_lock_connection] object_id: 279080, pg_backend_pid: 66102
ci: == [advisory_lock_connection] object_id: 279500, pg_backend_pid: 66104
ci: == 20230530112122 AddPathToOrganizations: migrating ===========================
ci: -- add_column(:organizations, :path, :text, {:null=>false, :default=>""})
ci:    -> 0.0034s
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0006s
ci: -- index_exists?(:organizations, :path, {:name=>"unique_organizations_on_path", :unique=>true, :algorithm=>:concurrently})
ci:    -> 0.0017s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0002s
ci: -- add_index(:organizations, :path, {:name=>"unique_organizations_on_path", :unique=>true, :algorithm=>:concurrently})
ci:    -> 0.0021s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0002s
ci: == 20230530112122 AddPathToOrganizations: migrated (0.0219s) ==================

ci: == 20230530112602 AddTextLimitOnOrganizationPath: migrating ===================
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- execute("ALTER TABLE organizations\nADD CONSTRAINT check_0b4296b5ea\nCHECK ( char_length(path) <= 255 )\nNOT VALID;\n")
ci:    -> 0.0010s
ci: -- execute("ALTER TABLE organizations VALIDATE CONSTRAINT check_0b4296b5ea;")
ci:    -> 0.0003s
ci: == 20230530112602 AddTextLimitOnOrganizationPath: migrated (0.0124s) ==========

ci: == 20230530114845 CleanupOrganizationsWithNullPath: migrating =================
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20230530114845 CleanupOrganizationsWithNullPath: migrated (0.0070s) ========

ci: == 20230530115830 RemoveDefaultOnOrganizationPath: migrating ==================
ci: -- change_column_default(:organizations, :path, nil)
ci:    -> 0.0023s
ci: == 20230530115830 RemoveDefaultOnOrganizationPath: migrated (0.0094s) =========

ci: == [advisory_lock_connection] object_id: 279500, pg_backend_pid: 66104
DOWN migration
main: == [advisory_lock_connection] object_id: 278840, pg_backend_pid: 71080
main: == 20230530115830 RemoveDefaultOnOrganizationPath: reverting ==================
main: -- change_column_default(:organizations, :path, "")
main:    -> 0.1085s
main: == 20230530115830 RemoveDefaultOnOrganizationPath: reverted (0.1127s) =========

main: == 20230530114845 CleanupOrganizationsWithNullPath: reverting =================
main: == 20230530114845 CleanupOrganizationsWithNullPath: reverted (0.0167s) ========

main: == 20230530112602 AddTextLimitOnOrganizationPath: reverting ===================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- execute("            ALTER TABLE organizations\n            DROP CONSTRAINT IF EXISTS check_0b4296b5ea\n")
main:    -> 0.0005s
main: == 20230530112602 AddTextLimitOnOrganizationPath: reverted (0.0156s) ==========

main: == 20230530112122 AddPathToOrganizations: reverting ===========================
main: -- remove_column(:organizations, :path, {:if_exists=>true})
main:    -> 0.0022s
main: == 20230530112122 AddPathToOrganizations: reverted (0.0047s) ==================

ci: == [advisory_lock_connection] object_id: 278780, pg_backend_pid: 71608
ci: == 20230530115830 RemoveDefaultOnOrganizationPath: reverting ==================
ci: -- change_column_default(:organizations, :path, "")
ci:    -> 0.0986s
ci: == 20230530115830 RemoveDefaultOnOrganizationPath: reverted (0.1073s) =========

ci: == 20230530114845 CleanupOrganizationsWithNullPath: reverting =================
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20230530114845 CleanupOrganizationsWithNullPath: reverted (0.0069s) ========

ci: == 20230530112602 AddTextLimitOnOrganizationPath: reverting ===================
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- execute("            ALTER TABLE organizations\n            DROP CONSTRAINT IF EXISTS check_0b4296b5ea\n")
ci:    -> 0.0006s
ci: == 20230530112602 AddTextLimitOnOrganizationPath: reverted (0.0171s) ==========

ci: == 20230530112122 AddPathToOrganizations: reverting ===========================
ci: -- remove_column(:organizations, :path, {:if_exists=>true})
ci:    -> 0.0022s
ci: == 20230530112122 AddPathToOrganizations: reverted (0.0090s) ==================

ci: == [advisory_lock_connection] object_id: 278780, pg_backend_pid: 71608

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

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 #410428 (closed)

Edited by Manoj M J

Merge request reports