summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorRegis Boudinot <boudinot.regis@yahoo.com>2017-05-10 22:07:05 +0000
committerRegis Boudinot <boudinot.regis@yahoo.com>2017-05-10 22:07:05 +0000
commit81df0034f4b66f2627ecd92f0ca44b7a3a634719 (patch)
tree1fc94d4e272b314dbe8b484e5c7d4cbf9faffb6c /db
parent4086fca0f4dba977874c4b79b46578d6d603bfc5 (diff)
parent7eaab72b983a89040a01b9f32184fef258fb29f2 (diff)
downloadgitlab-ce-81df0034f4b66f2627ecd92f0ca44b7a3a634719.tar.gz
Merge branch 'retried-in-database-mysql' into 'master'
Retried in database Closes #25737 See merge request !11115
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20170503004426_add_retried_to_ci_build.rb9
-rw-r--r--db/post_migrate/20170503004427_upate_retried_for_ci_build.rb29
-rw-r--r--db/schema.rb1
3 files changed, 39 insertions, 0 deletions
diff --git a/db/migrate/20170503004426_add_retried_to_ci_build.rb b/db/migrate/20170503004426_add_retried_to_ci_build.rb
new file mode 100644
index 00000000000..2851e3de473
--- /dev/null
+++ b/db/migrate/20170503004426_add_retried_to_ci_build.rb
@@ -0,0 +1,9 @@
+class AddRetriedToCiBuild < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def change
+ add_column(:ci_builds, :retried, :boolean)
+ end
+end
diff --git a/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb b/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb
new file mode 100644
index 00000000000..80215d662e4
--- /dev/null
+++ b/db/post_migrate/20170503004427_upate_retried_for_ci_build.rb
@@ -0,0 +1,29 @@
+class UpateRetriedForCiBuild < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ disable_statement_timeout
+
+ latest_id = <<-SQL.strip_heredoc
+ SELECT MAX(ci_builds2.id)
+ FROM ci_builds ci_builds2
+ WHERE ci_builds.commit_id=ci_builds2.commit_id
+ AND ci_builds.name=ci_builds2.name
+ SQL
+
+ # This is slow update as it does single-row query
+ # This is designed to be run as idle, or a post deployment migration
+ is_retried = Arel.sql("((#{latest_id}) != ci_builds.id)")
+
+ update_column_in_batches(:ci_builds, :retried, is_retried) do |table, query|
+ query.where(table[:retried].eq(nil))
+ end
+ end
+
+ def down
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index b91b3e6e977..6eaab4832e9 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -232,6 +232,7 @@ ActiveRecord::Schema.define(version: 20170508170547) do
t.integer "lock_version"
t.string "coverage_regex"
t.integer "auto_canceled_by_id"
+ t.boolean "retried"
end
add_index "ci_builds", ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree