Skip to content

Add creator relationship to namespaces

Ian Anderson requested to merge add-created-by-association-to-groups into master

What does this MR do and why?

Related to: https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/625

This MR adds a creator relationship to namespaces. This relationship will be used to limit the number of groups a user can create before they complete identity verification.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Up migration:

▶ ./bin/rake db:migrate:main
main: == [advisory_lock_connection] object_id: 124340, pg_backend_pid: 1855988
main: == 20240418181719 AddCreatedByToNamespaceDetails: migrating ===================
main: -- add_column(:namespace_details, :creator_id, :bigint)
main:    -> 0.0013s
main: == 20240418181719 AddCreatedByToNamespaceDetails: migrated (0.0043s) ==========

main: == 20240429171415 AddIndexToNamespaceDetails: migrating =======================
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0028s
main: -- index_exists?(:namespace_details, :creator_id, {:name=>"index_namespace_details_on_creator_id", :algorithm=>:concurrently})
main:    -> 0.0013s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- add_index(:namespace_details, :creator_id, {:name=>"index_namespace_details_on_creator_id", :algorithm=>:concurrently})
main:    -> 0.0008s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20240429171415 AddIndexToNamespaceDetails: migrated (0.0158s) ==============

Down migration:

▶ ./bin/rake db:migrate:down:main VERSION=20240429171415
main: == [advisory_lock_connection] object_id: 124060, pg_backend_pid: 1858892
main: == 20240429171415 AddIndexToNamespaceDetails: reverting =======================
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0031s
main: -- indexes(:namespace_details)
main:    -> 0.0018s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0003s
main: -- remove_index(:namespace_details, {:algorithm=>:concurrently, :name=>"index_namespace_details_on_creator_id"})
main:    -> 0.0009s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20240429171415 AddIndexToNamespaceDetails: reverted (0.0187s) ==============

main: == [advisory_lock_connection] object_id: 124060, pg_backend_pid: 1858892

▶ ./bin/rake db:migrate:down:main VERSION=20240418181719
main: == [advisory_lock_connection] object_id: 124060, pg_backend_pid: 1859622
main: == 20240418181719 AddCreatedByToNamespaceDetails: reverting ===================
main: -- remove_column(:namespace_details, :creator_id, :bigint)
main:    -> 0.0009s
main: == 20240418181719 AddCreatedByToNamespaceDetails: reverted (0.0062s) ==========

main: == [advisory_lock_connection] object_id: 124060, pg_backend_pid: 1859622

How to set up and validate locally

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

  1. Run the migrations
bin/rails db:migrate RAILS_ENV=development
  1. Create a group and verify that the relationships exist
[48] pry(main)> u = User.last
=> #<User id:172 @new60>
[49] pry(main)> Groups::CreateService.new(u, {"name"=>"test-123", "path"=>"test-123", "visibility_level"=>"0", "request_access_enabled" => "1"}).execute
=> #<ServiceResponse:0x00007f799c05a5b0 @http_status=:ok, @message=nil, @payload={:group=>#<Group id:229 @test-123>}, @reason=nil, @status=:success>
[50] pry(main)> g = Group.last
=> #<Group id:266 @test-123>
[51] pry(main)> g.namespace_details.creator
=> #<User id:172 @User>
[52] pry(main)> u.created_namespace_details
=> [#<Namespace::Detail:0x00007fe3e88e8fe0
  namespace_id: 266,
  created_at: Tue, 23 Apr 2024 16:44:26.206224000 UTC +00:00,
  updated_at: Tue, 23 Apr 2024 16:44:26.348767000 UTC +00:00,
  cached_markdown_version: 2162688,
  description: "[FILTERED]",
  description_html: "",
  creator_id: 172>]
Edited by Ian Anderson

Merge request reports

Loading