diff --git a/db/migrate/20180508102840_add_unique_constraint_to_project_mirror_data_project_id_index.rb b/db/migrate/20180508102840_add_unique_constraint_to_project_mirror_data_project_id_index.rb new file mode 100644 index 0000000000000000000000000000000000000000..acb976b52fa3b7dbdeb1636758fe2ca40712287e --- /dev/null +++ b/db/migrate/20180508102840_add_unique_constraint_to_project_mirror_data_project_id_index.rb @@ -0,0 +1,31 @@ +class AddUniqueConstraintToProjectMirrorDataProjectIdIndex < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index(:project_mirror_data, + :project_id, + unique: true, + name: 'index_project_mirror_data_on_project_id_unique') + + remove_concurrent_index_by_name(:project_mirror_data, 'index_project_mirror_data_on_project_id') + + rename_index(:project_mirror_data, + 'index_project_mirror_data_on_project_id_unique', + 'index_project_mirror_data_on_project_id') + end + + def down + rename_index(:project_mirror_data, + 'index_project_mirror_data_on_project_id', + 'index_project_mirror_data_on_project_id_old') + + add_concurrent_index(:project_mirror_data, :project_id) + + remove_concurrent_index_by_name(:project_mirror_data, + 'index_project_mirror_data_on_project_id_old') + end +end diff --git a/db/schema.rb b/db/schema.rb index 6f40f70d350471b5303f4d18cc46fb8c0defd95f..ec0aa5f6603411ac25415624c5cd3d22e5a19a07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180508100222) do +ActiveRecord::Schema.define(version: 20180508102840) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1536,7 +1536,7 @@ ActiveRecord::Schema.define(version: 20180508100222) do end add_index "project_mirror_data", ["jid"], name: "index_project_mirror_data_on_jid", using: :btree - add_index "project_mirror_data", ["project_id"], name: "index_project_mirror_data_on_project_id", using: :btree + add_index "project_mirror_data", ["project_id"], name: "index_project_mirror_data_on_project_id", unique: true, using: :btree add_index "project_mirror_data", ["status"], name: "index_project_mirror_data_on_status", using: :btree create_table "project_statistics", force: :cascade do |t|