Commit 4c8d478e authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'fix-retried-for-postgres' into 'master'

Fix migrations for older PostgreSQL versions

Closes #32721

See merge request !11620
parents ad47f209 92ec0ae0
...@@ -52,7 +52,7 @@ stages: ...@@ -52,7 +52,7 @@ stages:
.use-pg: &use-pg .use-pg: &use-pg
services: services:
- postgres:latest - postgres:9.2
- redis:alpine - redis:alpine
.use-mysql: &use-mysql .use-mysql: &use-mysql
......
---
title: Fix migration for older PostgreSQL versions
merge_request:
author:
class UpateRetriedForCiBuild < ActiveRecord::Migration class UpdateRetriedForCiBuild < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
DOWNTIME = false DOWNTIME = false
...@@ -54,13 +54,15 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration ...@@ -54,13 +54,15 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration
def with_temporary_partial_index def with_temporary_partial_index
if Gitlab::Database.postgresql? if Gitlab::Database.postgresql?
execute 'CREATE INDEX CONCURRENTLY IF NOT EXISTS index_for_ci_builds_retried_migration ON ci_builds (id) WHERE retried IS NULL;' unless index_exists?(:ci_builds, name: :index_for_ci_builds_retried_migration)
execute 'CREATE INDEX CONCURRENTLY index_for_ci_builds_retried_migration ON ci_builds (id) WHERE retried IS NULL;'
end
end end
yield yield
if Gitlab::Database.postgresql? if Gitlab::Database.postgresql? && index_exists?(:ci_builds, name: :index_for_ci_builds_retried_migration)
execute 'DROP INDEX CONCURRENTLY IF EXISTS index_for_ci_builds_retried_migration' execute 'DROP INDEX CONCURRENTLY index_for_ci_builds_retried_migration'
end end
end end
end end
require 'spec_helper' require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170503004427_upate_retried_for_ci_build.rb') require Rails.root.join('db', 'post_migrate', '20170503004427_update_retried_for_ci_build.rb')
describe UpateRetriedForCiBuild, truncate: true do describe UpdateRetriedForCiBuild, truncate: true do
let(:pipeline) { create(:ci_pipeline) } let(:pipeline) { create(:ci_pipeline) }
let!(:build_old) { create(:ci_build, pipeline: pipeline, name: 'test') } let!(:build_old) { create(:ci_build, pipeline: pipeline, name: 'test') }
let!(:build_new) { create(:ci_build, pipeline: pipeline, name: 'test') } let!(:build_new) { create(:ci_build, pipeline: pipeline, name: 'test') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment