summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKushal Pandya <kushalspandya@gmail.com>2017-05-23 07:18:08 +0000
committerKushal Pandya <kushalspandya@gmail.com>2017-05-23 07:18:08 +0000
commit4c8d478eefc4b50ffc26f0d1ce159470ae9f0105 (patch)
tree5fce597240dbb0bd2932457a73c612352f88c4f8
parentad47f2094bf61867d2b5e4c24540c7c5b8a6358d (diff)
parent92ec0ae0a7997aa841106432a319be51b2d446a0 (diff)
downloadgitlab-ce-4c8d478eefc4b50ffc26f0d1ce159470ae9f0105.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 45f1638f871..3af2d4adc13 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -52,7 +52,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 738e46b9207..705e11ed47d 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') }