Skip to content

WIP: Resolve "Clean up schema for table trending_projects"

Andreas Brandl requested to merge 32283-trending-projects-unique-constraint into master

This turns an existing index on trending_projects#project_id into a UNIQUE index. See https://gitlab.com/gitlab-org/gitlab-ce/issues/32283.

Database Checklist

When adding migrations:

  • Updated db/schema.rb
  • Added a down method so the migration can be reverted
  • Added the output of the migration(s) to the MR body
  • Added tests for the migration in spec/migrations if necessary (e.g. when migrating data)

Output of migrations run locally:

$ rake db:migrate;                                                                                                                                                                                                                     [18:50:21]
== 20180131101039 RemoveDuplicatesInTrendingProjects: migrating ===============
== 20180131101039 RemoveDuplicatesInTrendingProjects: migrated (0.0011s) ======

== 20180131101040 AddUniqueConstraintToTrendingProjectsProjectId: migrating ===
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0003s
-- add_index(:trending_projects, :project_id, {:unique=>true, :name=>"index_trending_projects_on_project_id_new", :algorithm=>:concurrently})
   -> 0.0120s
-- remove_foreign_key(:trending_projects, :projects)
   -> 0.0049s
-- transaction_open?()
   -> 0.0000s
-- select_one("SELECT current_setting('server_version_num') AS v")
   -> 0.0004s
-- execute("SET statement_timeout TO 0")
   -> 0.0003s
-- remove_index(:trending_projects, {:name=>"index_trending_projects_on_project_id", :algorithm=>:concurrently, :column=>:project_id})
   -> 0.0025s
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0003s
-- execute("ALTER TABLE trending_projects\nADD CONSTRAINT fk_09feecd872\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0020s
-- execute("ALTER TABLE trending_projects VALIDATE CONSTRAINT fk_09feecd872;")
   -> 0.0023s
-- rename_index(:trending_projects, "index_trending_projects_on_project_id_new", "index_trending_projects_on_project_id")
   -> 0.0015s
== 20180131101040 AddUniqueConstraintToTrendingProjectsProjectId: migrated (0.0272s) 

General Checklist

Edited by Andreas Brandl

Merge request reports