diff --git a/db/migrate/20180424160449_add_pipeline_iid_to_ci_pipelines.rb b/db/migrate/20180424160449_add_pipeline_iid_to_ci_pipelines.rb index d732116e9ce..128377e1c9d 100644 --- a/db/migrate/20180424160449_add_pipeline_iid_to_ci_pipelines.rb +++ b/db/migrate/20180424160449_add_pipeline_iid_to_ci_pipelines.rb @@ -6,10 +6,10 @@ class AddPipelineIidToCiPipelines < ActiveRecord::Migration disable_ddl_transaction! def up - add_column :ci_pipelines, :iid, :integer + add_column :ci_pipelines, :iid_per_project, :integer end def down - remove_column :ci_pipelines, :iid, :integer + remove_column :ci_pipelines, :iid_per_project, :integer end end diff --git a/db/migrate/20180425205249_add_index_constraints_to_pipeline_iid.rb b/db/migrate/20180425205249_add_index_constraints_to_pipeline_iid.rb new file mode 100644 index 00000000000..7daa7197b7c --- /dev/null +++ b/db/migrate/20180425205249_add_index_constraints_to_pipeline_iid.rb @@ -0,0 +1,15 @@ +class AddIndexConstraintsToPipelineIid < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :ci_pipelines, [:project_id, :iid_per_project], unique: true, where: 'iid_per_project IS NOT NULL' + end + + def down + remove_concurrent_index :ci_pipelines, [:project_id, :iid_per_project] + end +end diff --git a/db/schema.rb b/db/schema.rb index d4bc075eb2e..af838e109b2 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: 20180425131009) do +ActiveRecord::Schema.define(version: 20180425205249) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -434,11 +434,12 @@ ActiveRecord::Schema.define(version: 20180425131009) do t.integer "config_source" t.boolean "protected" t.integer "failure_reason" - t.integer "iid" + t.integer "iid_per_project" end add_index "ci_pipelines", ["auto_canceled_by_id"], name: "index_ci_pipelines_on_auto_canceled_by_id", using: :btree add_index "ci_pipelines", ["pipeline_schedule_id"], name: "index_ci_pipelines_on_pipeline_schedule_id", using: :btree + add_index "ci_pipelines", ["project_id", "iid_per_project"], name: "index_ci_pipelines_on_project_id_and_iid_per_project", unique: true, where: "(iid_per_project IS NOT NULL)", using: :btree add_index "ci_pipelines", ["project_id", "ref", "status", "id"], name: "index_ci_pipelines_on_project_id_and_ref_and_status_and_id", using: :btree add_index "ci_pipelines", ["project_id", "sha"], name: "index_ci_pipelines_on_project_id_and_sha", using: :btree add_index "ci_pipelines", ["project_id"], name: "index_ci_pipelines_on_project_id", using: :btree