Skip to content

Add project ID to timelogs

Lee Tickett requested to merge add-prpoject_id-to-timelogs into master

What does this MR do?

Before we can implement !57322 (merged) we need to improve the query performance, and the best approach to that is adding project_id to timelogs.

This MR adds the column and FK relationship. A follow up MR will migrate the date and aim to make the column non-nullable.

/cc @sabrams

Screenshots (strongly suggested)

lee@cc-gdk-2:~/gitlab-development-kit/gitlab$ bundle exec rake db:migrate:up VERSION=20210422181809 RAILS_ENV=development
== 20210422181809 AddProjectToTimelogs: migrating =============================
-- add_column(:timelogs, :project_id, :integer)
   -> 0.0011s
== 20210422181809 AddProjectToTimelogs: migrated (0.0060s) ====================

lee@cc-gdk-2:~/gitlab-development-kit/gitlab$ bundle exec rake db:migrate:up VERSION=20210424163400 RAILS_ENV=development
== 20210424163400 AddProjectIdFkToTimelogs: migrating =========================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:timelogs, [:project_id, :spent_at], {:name=>"index_timelogs_on_project_id_and_spent_at ", :algorithm=>:concurrently})
   -> 0.0026s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- add_index(:timelogs, [:project_id, :spent_at], {:name=>"index_timelogs_on_project_id_and_spent_at ", :algorithm=>:concurrently})
   -> 0.0030s
-- execute("RESET ALL")
   -> 0.0005s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:timelogs)
   -> 0.0021s
-- execute("ALTER TABLE timelogs\nADD CONSTRAINT fk_c49c83dd77\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0013s
-- execute("ALTER TABLE timelogs VALIDATE CONSTRAINT fk_c49c83dd77;")
   -> 0.0022s
== 20210424163400 AddProjectIdFkToTimelogs: migrated (0.0189s) ================

lee@cc-gdk-2:~/gitlab-development-kit/gitlab$ bundle exec rake db:migrate:down VERSION=20210424163400 RAILS_ENV=development
== 20210424163400 AddProjectIdFkToTimelogs: reverting =========================
-- foreign_keys(:timelogs)
   -> 0.0026s
-- remove_foreign_key(:timelogs, {:column=>:project_id})
   -> 0.0048s
-- transaction_open?()
   -> 0.0000s
-- indexes(:timelogs)
   -> 0.0025s
-- execute("SET statement_timeout TO 0")
   -> 0.0004s
-- remove_index(:timelogs, {:algorithm=>:concurrently, :name=>"index_timelogs_on_project_id_and_spent_at "})
   -> 0.0013s
-- execute("RESET ALL")
   -> 0.0005s
== 20210424163400 AddProjectIdFkToTimelogs: reverted (0.0132s) ================

lee@cc-gdk-2:~/gitlab-development-kit/gitlab$ bundle exec rake db:migrate:down VERSION=20210422181809 RAILS_ENV=development
== 20210422181809 AddProjectToTimelogs: reverting =============================
-- remove_column(:timelogs, :project_id)
   -> 0.0011s
== 20210422181809 AddProjectToTimelogs: reverted (0.0502s) ====================

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Alex Kalderimis

Merge request reports