diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-02-02 18:33:37 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-02-02 18:33:37 +0300 |
commit | f6699fbcd74670edd9a20c8d92b412f53ffe3b4c (patch) | |
tree | 9f5f56a71ca53f79bd7225801f70400c92f04f31 | |
parent | 24aa512610e142f2945ed55ac448af38fe672e51 (diff) | |
parent | 313f4d49d7aea0318bbabeae529d58076519aea0 (diff) |
Merge branch '32283-trending-projects-unique-constraint2' into 'master'
Add unique constraint to trending_projects#project_id.
See merge request gitlab-org/gitlab-ce!16846
-rw-r--r-- | changelogs/unreleased/32283-trending-projects-unique-constraint2.yml | 5 | ||||
-rw-r--r-- | db/migrate/20180201102129_add_unique_constraint_to_trending_projects_project_id.rb | 19 | ||||
-rw-r--r-- | db/schema.rb | 2 |
3 files changed, 25 insertions, 1 deletions
diff --git a/changelogs/unreleased/32283-trending-projects-unique-constraint2.yml b/changelogs/unreleased/32283-trending-projects-unique-constraint2.yml new file mode 100644 index 00000000000..4fd6b6fddc4 --- /dev/null +++ b/changelogs/unreleased/32283-trending-projects-unique-constraint2.yml @@ -0,0 +1,5 @@ +--- +title: Add unique constraint to trending_projects#project_id. +merge_request: 16846 +author: +type: other diff --git a/db/migrate/20180201102129_add_unique_constraint_to_trending_projects_project_id.rb b/db/migrate/20180201102129_add_unique_constraint_to_trending_projects_project_id.rb new file mode 100644 index 00000000000..02e53b8fa8a --- /dev/null +++ b/db/migrate/20180201102129_add_unique_constraint_to_trending_projects_project_id.rb @@ -0,0 +1,19 @@ +class AddUniqueConstraintToTrendingProjectsProjectId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :trending_projects, :project_id, unique: true, name: 'index_trending_projects_on_project_id_unique' + remove_concurrent_index_by_name :trending_projects, 'index_trending_projects_on_project_id' + rename_index :trending_projects, 'index_trending_projects_on_project_id_unique', 'index_trending_projects_on_project_id' + end + + def down + rename_index :trending_projects, 'index_trending_projects_on_project_id', 'index_trending_projects_on_project_id_old' + add_concurrent_index :trending_projects, :project_id + remove_concurrent_index_by_name :trending_projects, 'index_trending_projects_on_project_id_old' + end +end diff --git a/db/schema.rb b/db/schema.rb index f72989ff391..c701a5f1e17 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1727,7 +1727,7 @@ ActiveRecord::Schema.define(version: 20180202111106) do t.integer "project_id", null: false end - add_index "trending_projects", ["project_id"], name: "index_trending_projects_on_project_id", using: :btree + add_index "trending_projects", ["project_id"], name: "index_trending_projects_on_project_id", unique: true, using: :btree create_table "u2f_registrations", force: :cascade do |t| t.text "certificate" |