summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Stark <stark@gitlab.com>2017-09-19 22:47:04 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2017-09-26 11:33:20 +0200
commit23b58e54680e5a73a2e81960114504e6a8a161cf (patch)
tree83bca450ffd5db033ef3c877eb0fdaedd8c83776
parenta7265abd6dc397017381763ea22250656105ae10 (diff)
downloadgitlab-ce-remove-temporary-ci-index.tar.gz
Remove an unneeded index on ci_builds left in some databasesremove-temporary-ci-index
Migration 20170919211300_remove_temporary_ci_builds_index.rb created a temporary partial index and tried to drop it at the end of the migration. In some circumstances apparently it failed to drop the index and it ended up in our schema.rb. This accidentally failed to fail due to a bug in the regular expression for partial indexes which caused the index creation in schema.rb to be ignored. Now that that's fixed we could be resurrecting this zombie index from the past in some but not all databases. Add a migration to drop this index if it's present to reconcile this discrepancy.
-rw-r--r--changelogs/unreleased/remove-temporary-ci-index.yml5
-rw-r--r--db/migrate/20170919211300_remove_temporary_ci_builds_index.rb27
-rw-r--r--db/schema.rb1
3 files changed, 32 insertions, 1 deletions
diff --git a/changelogs/unreleased/remove-temporary-ci-index.yml b/changelogs/unreleased/remove-temporary-ci-index.yml
new file mode 100644
index 00000000000..a319f7fff7f
--- /dev/null
+++ b/changelogs/unreleased/remove-temporary-ci-index.yml
@@ -0,0 +1,5 @@
+---
+title: Remove an index on ci_builds meant to be only temporary
+merge_request:
+author:
+type: other
diff --git a/db/migrate/20170919211300_remove_temporary_ci_builds_index.rb b/db/migrate/20170919211300_remove_temporary_ci_builds_index.rb
new file mode 100644
index 00000000000..b2009b282e9
--- /dev/null
+++ b/db/migrate/20170919211300_remove_temporary_ci_builds_index.rb
@@ -0,0 +1,27 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class RemoveTemporaryCiBuildsIndex < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ # To use create/remove index concurrently
+ disable_ddl_transaction!
+
+ def up
+ return unless index_exists?(:ci_builds, :id, name: 'index_for_ci_builds_retried_migration')
+ remove_concurrent_index(:ci_builds, :id, name: "index_for_ci_builds_retried_migration")
+ end
+
+ def down
+ # this was a temporary index for a migration that was never
+ # present previously so this probably shouldn't be here but it's
+ # easier to test the drop if we have a way to create it.
+ add_concurrent_index("ci_builds", ["id"],
+ name: "index_for_ci_builds_retried_migration",
+ where: "(retried IS NULL)",
+ using: :btree)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 80ef91ec95d..330336e8e61 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -256,7 +256,6 @@ ActiveRecord::Schema.define(version: 20170921115009) do
add_index "ci_builds", ["commit_id", "status", "type"], name: "index_ci_builds_on_commit_id_and_status_and_type", using: :btree
add_index "ci_builds", ["commit_id", "type", "name", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_name_and_ref", using: :btree
add_index "ci_builds", ["commit_id", "type", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_ref", using: :btree
- add_index "ci_builds", ["id"], name: "index_for_ci_builds_retried_migration", where: "(retried IS NULL)", using: :btree
add_index "ci_builds", ["project_id"], name: "index_ci_builds_on_project_id", using: :btree
add_index "ci_builds", ["protected"], name: "index_ci_builds_on_protected", using: :btree
add_index "ci_builds", ["runner_id"], name: "index_ci_builds_on_runner_id", using: :btree