Skip to content

Add a worker to remove legacy open-source license from inactive projects

What does this MR do and why?

Add a worker to remove the legacy open-source license from projects after 1 year of inactivity.

Migration output

up
bin/rails db:migrate:up:main VERSION=20220729033851
WARNING: This version of GitLab depends on gitlab-shell 14.10.0, but you're running 14.9.0. Please update gitlab-shell.
main: == 20220729033851 AddPartialLegacyOpenSourceLicenseAvailableIndex: migrating ==
main: -- transaction_open?()
main:    -> 0.0000s
main: -- index_exists?(:project_settings, [:legacy_open_source_license_available], {:where=>"legacy_open_source_license_available = TRUE", :name=>"index_project_settings_on_legacy_open_source_license_available", :algorithm=>:concurrently})
main:    -> 0.0038s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- add_index(:project_settings, [:legacy_open_source_license_available], {:where=>"legacy_open_source_license_available = TRUE", :name=>"index_project_settings_on_legacy_open_source_license_available", :algorithm=>:concurrently})
main:    -> 0.0016s
main: -- execute("RESET statement_timeout")
main:    -> 0.0001s
main: == 20220729033851 AddPartialLegacyOpenSourceLicenseAvailableIndex: migrated (0.0099s)
down
bin/rails db:migrate:down:main VERSION=20220729033851
WARNING: This version of GitLab depends on gitlab-shell 14.10.0, but you're running 14.9.0. Please update gitlab-shell.
main: == 20220729033851 AddPartialLegacyOpenSourceLicenseAvailableIndex: reverting ==
main: -- transaction_open?()
main:    -> 0.0000s
main: -- indexes(:project_settings)
main:    -> 0.0046s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- remove_index(:project_settings, {:algorithm=>:concurrently, :name=>"index_project_settings_on_legacy_open_source_license_available"})
main:    -> 0.0020s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20220729033851 AddPartialLegacyOpenSourceLicenseAvailableIndex: reverted (0.0115s)

Query plan

Sample Query
UPDATE "project_settings"
SET "legacy_open_source_license_available" = FALSE
WHERE "project_settings"."project_id" IN (SELECT "projects"."id"
                                          FROM "projects"
                                                   INNER JOIN "project_settings" ON "project_settings"."project_id" = "projects"."id"
                                          WHERE "projects"."visibility_level" = 20
                                            AND (projects.last_activity_at < '2021-08-02 01:11:00.373910')
                                            AND "project_settings"."legacy_open_source_license_available" = TRUE
                                          LIMIT 500)

Before adding index

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/11276/commands/40365

After adding index

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/11276/commands/40371

Index on postgres.ai

exec CREATE INDEX index_project_settings_on_legacy_open_source_license_available ON project_settings (legacy_open_source_license_available) WHERE legacy_open_source_license_available = TRUE

The query has been executed. Duration: 7.006 s

List of relations

Schema Name Type Owner Table Size Description
public index_project_settings_on_legacy_open_source_license_available index joe_887 project_settings 16 MB
(1 row)

How to set up and validate locally

  1. Update the last_activity_at for some public projects to a year ago: projects.update(last_activity_at: 1.year.ago).
  2. Update their license to legacy open-source license: ProjectSetting.where(project_id: project_ids).update(legacy_open_source_license_available: true)
  3. gdk restart
  4. Go to the Sidekiq cron http://localhost:3000/admin/sidekiq/cron and click on Enqueue Now for disable_legacy_open_source_license_for_inactive_projects cron.
  5. The license for the above project_ids should be false: ProjectSetting.where(project_id: project_ids).pluck(:legacy_open_source_license_available)

MR acceptance checklist

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

Closes #364502

Edited by Abdul Wadood

Merge request reports

Loading