Add project ID to timelogs
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
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because _____.
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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