Skip to content

Resolve "Organizations can have non-unique names"

Manoj M J requested to merge 410428-organization-model-has-a-path-attribute into master

What does this MR do and why?

This is the first step towards building #410428 (closed).

organizations needs a path attribute, but we currently do not have it, and only have a name attribute.

This name attribute is currently set to be unique, but this isn't right, as multiple organizations can have the same, but only it's path should differ (just like group and project names)

As first step, before introducing path on organizations, we are removing the uniqueness constraint on organizations.name with this MR.

To note: organizations is a table with only one record now, the default organization, so this is a small table with no traffic, as we do not yet allow to create organizations via UI or API.

Migrations

Up migration
main: == [advisory_lock_connection] object_id: 275800, pg_backend_pid: 10599
main: == 20230524095108 RemoveIndexOnNameOnOrganization: migrating ==================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0700s
main: -- indexes(:organizations)
main:    -> 0.0015s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- remove_index(:organizations, {:algorithm=>:concurrently, :name=>"unique_organizations_on_name_lower"})
main:    -> 0.0021s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20230524095108 RemoveIndexOnNameOnOrganization: migrated (0.0850s) =========

main: == [advisory_lock_connection] object_id: 275800, pg_backend_pid: 10599
ci: == [advisory_lock_connection] object_id: 276000, pg_backend_pid: 10602
ci: == 20230524095108 RemoveIndexOnNameOnOrganization: migrating ==================
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0053s
ci: -- indexes(:organizations)
ci:    -> 0.0048s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0024s
ci: -- remove_index(:organizations, {:algorithm=>:concurrently, :name=>"unique_organizations_on_name_lower"})
ci:    -> 0.0047s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0021s
ci: == 20230524095108 RemoveIndexOnNameOnOrganization: migrated (0.0655s) =========

ci: == [advisory_lock_connection] object_id: 276000, pg_backend_pid: 10602
Down migration
main: == [advisory_lock_connection] object_id: 276640, pg_backend_pid: 11445
main: == 20230524095108 RemoveIndexOnNameOnOrganization: reverting ==================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0961s
main: -- index_exists?(:organizations, "lower(name)", {:name=>"unique_organizations_on_name_lower", :algorithm=>:concurrently})
main:    -> 0.0016s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- add_index(:organizations, "lower(name)", {:name=>"unique_organizations_on_name_lower", :algorithm=>:concurrently})
main:    -> 0.0043s
main: -- execute("RESET statement_timeout")
main:    -> 0.0003s
main: == 20230524095108 RemoveIndexOnNameOnOrganization: reverted (0.1159s) =========

ci: == [advisory_lock_connection] object_id: 275600, pg_backend_pid: 11047


ci: == 20230524095108 RemoveIndexOnNameOnOrganization: reverting ==================
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.1038s
ci: -- index_exists?(:organizations, "lower(name)", {:name=>"unique_organizations_on_name_lower", :algorithm=>:concurrently})
ci:    -> 0.0015s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0004s
ci: -- add_index(:organizations, "lower(name)", {:name=>"unique_organizations_on_name_lower", :algorithm=>:concurrently})
ci:    -> 0.0047s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0003s
ci: == 20230524095108 RemoveIndexOnNameOnOrganization: reverted (0.1285s) =========

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

Loading