summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKushal Pandya <kushalspandya@gmail.com>2017-05-23 07:18:08 +0000
committerkushalpandya <kushal@gitlab.com>2017-05-23 13:35:52 +0530
commit078638a6ab0161ede25653484fd7e37df7f8708e (patch)
treebfe6f2f089fe440414d07593ff7bdbeda90cbf0e
parentd753c1c355188083759385ca77de2b515d279336 (diff)
downloadgitlab-ce-078638a6ab0161ede25653484fd7e37df7f8708e.tar.gz
Merge branch 'fix-retried-for-postgres' into 'master'
Fix migrations for older PostgreSQL versions Closes #32721 See merge request !11620
-rw-r--r--.gitlab-ci.yml2
-rw-r--r--changelogs/unreleased/fix-migration-for-postgres.yml4
-rw-r--r--db/post_migrate/20170503004427_update_retried_for_ci_build.rb (renamed from db/post_migrate/20170503004427_upate_retried_for_ci_build.rb)10
-rw-r--r--spec/migrations/update_retried_for_ci_builds_spec.rb (renamed from spec/migrations/upate_retried_for_ci_builds_spec.rb)4
4 files changed, 13 insertions, 7 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4ff6663c130..23d2e48662c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -51,7 +51,7 @@ stages:
.use-pg: &use-pg
services:
- - postgres:latest
+ - postgres:9.2
- redis:alpine
.use-mysql: &use-mysql
diff --git a/changelogs/unreleased/fix-migration-for-postgres.yml b/changelogs/unreleased/fix-migration-for-postgres.yml
new file mode 100644
index 00000000000..dda7051c8f5
--- /dev/null
+++ b/changelogs/unreleased/fix-migration-for-postgres.yml
@@ -0,0 +1,4 @@
+---
+title: Fix migration for older PostgreSQL versions
+merge_request:
+author:
diff --git a/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb b/db/post_migrate/20170503004427_update_retried_for_ci_build.rb
index 3096c54acb7..3a4d6c4916b 100644
--- a/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb
+++ b/db/post_migrate/20170503004427_update_retried_for_ci_build.rb
@@ -1,4 +1,4 @@
-class UpateRetriedForCiBuild < ActiveRecord::Migration
+class UpdateRetriedForCiBuild < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
@@ -54,13 +54,15 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration
def with_temporary_partial_index
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
yield
- if Gitlab::Database.postgresql?
- execute 'DROP INDEX CONCURRENTLY IF EXISTS index_for_ci_builds_retried_migration'
+ if Gitlab::Database.postgresql? && index_exists?(:ci_builds, name: :index_for_ci_builds_retried_migration)
+ execute 'DROP INDEX CONCURRENTLY index_for_ci_builds_retried_migration'
end
end
end
diff --git a/spec/migrations/upate_retried_for_ci_builds_spec.rb b/spec/migrations/update_retried_for_ci_builds_spec.rb
index 5cdb8a3c7da..3742b4dafe5 100644
--- a/spec/migrations/upate_retried_for_ci_builds_spec.rb
+++ b/spec/migrations/update_retried_for_ci_builds_spec.rb
@@ -1,7 +1,7 @@
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!(:build_old) { create(:ci_build, pipeline: pipeline, name: 'test') }
let!(:build_new) { create(:ci_build, pipeline: pipeline, name: 'test') }