summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/fixtures/development/14_builds.rb2
-rw-r--r--db/migrate/20160412173416_add_fields_to_ci_commit.rb8
-rw-r--r--db/migrate/20160412173417_update_ci_commit.rb35
-rw-r--r--db/migrate/20160412173418_add_ci_commit_indexes.rb19
-rw-r--r--db/schema.rb7
5 files changed, 70 insertions, 1 deletions
diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb
index e3ca2b4eea3..b99d24a03c9 100644
--- a/db/fixtures/development/14_builds.rb
+++ b/db/fixtures/development/14_builds.rb
@@ -19,7 +19,7 @@ class Gitlab::Seeder::Builds
commits = @project.repository.commits('master', nil, 5)
commits_sha = commits.map { |commit| commit.raw.id }
commits_sha.map do |sha|
- @project.ensure_ci_commit(sha)
+ @project.ensure_ci_commit(sha, 'master')
end
rescue
[]
diff --git a/db/migrate/20160412173416_add_fields_to_ci_commit.rb b/db/migrate/20160412173416_add_fields_to_ci_commit.rb
new file mode 100644
index 00000000000..125956a3ddd
--- /dev/null
+++ b/db/migrate/20160412173416_add_fields_to_ci_commit.rb
@@ -0,0 +1,8 @@
+class AddFieldsToCiCommit < ActiveRecord::Migration
+ def change
+ add_column :ci_commits, :status, :string
+ add_column :ci_commits, :started_at, :timestamp
+ add_column :ci_commits, :finished_at, :timestamp
+ add_column :ci_commits, :duration, :integer
+ end
+end
diff --git a/db/migrate/20160412173417_update_ci_commit.rb b/db/migrate/20160412173417_update_ci_commit.rb
new file mode 100644
index 00000000000..fd92444dbac
--- /dev/null
+++ b/db/migrate/20160412173417_update_ci_commit.rb
@@ -0,0 +1,35 @@
+class UpdateCiCommit < ActiveRecord::Migration
+ # This migration can be run online, but needs to be executed for the second time after restarting Unicorn workers
+ # Otherwise Offline migration should be used.
+ def change
+ execute("UPDATE ci_commits SET status=#{status}, ref=#{ref}, tag=#{tag} WHERE status IS NULL")
+ end
+
+ private
+
+ def status
+ builds = '(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id)'
+ success = "(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id AND status='success')"
+ ignored = "(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id AND (status='failed' OR status='canceled') AND allow_failure)"
+ pending = "(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id AND status='pending')"
+ running = "(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id AND status='running')"
+ canceled = "(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id AND status='canceled')"
+
+ "(CASE
+ WHEN #{builds}=0 THEN 'skipped'
+ WHEN #{builds}=#{success}+#{ignored} THEN 'success'
+ WHEN #{builds}=#{pending} THEN 'pending'
+ WHEN #{builds}=#{canceled} THEN 'canceled'
+ WHEN #{running}+#{pending}>0 THEN 'running'
+ ELSE 'failed'
+ END)"
+ end
+
+ def ref
+ '(SELECT ref FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id ORDER BY id DESC LIMIT 1)'
+ end
+
+ def tag
+ '(SELECT tag FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id ORDER BY id DESC LIMIT 1)'
+ end
+end
diff --git a/db/migrate/20160412173418_add_ci_commit_indexes.rb b/db/migrate/20160412173418_add_ci_commit_indexes.rb
new file mode 100644
index 00000000000..603d4a41610
--- /dev/null
+++ b/db/migrate/20160412173418_add_ci_commit_indexes.rb
@@ -0,0 +1,19 @@
+class AddCiCommitIndexes < ActiveRecord::Migration
+ disable_ddl_transaction!
+
+ def change
+ add_index :ci_commits, [:gl_project_id, :sha], index_options
+ add_index :ci_commits, [:gl_project_id, :status], index_options
+ add_index :ci_commits, [:status], index_options
+ end
+
+ private
+
+ def index_options
+ if Gitlab::Database.postgresql?
+ { algorithm: :concurrently }
+ else
+ { }
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 0ab32cab8b4..cda592a99fd 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -170,14 +170,21 @@ ActiveRecord::Schema.define(version: 20160415133440) do
t.text "yaml_errors"
t.datetime "committed_at"
t.integer "gl_project_id"
+ t.string "status"
+ t.datetime "started_at"
+ t.datetime "finished_at"
+ t.integer "duration"
end
+ add_index "ci_commits", ["gl_project_id", "sha"], name: "index_ci_commits_on_gl_project_id_and_sha", using: :btree
+ add_index "ci_commits", ["gl_project_id", "status"], name: "index_ci_commits_on_gl_project_id_and_status", using: :btree
add_index "ci_commits", ["gl_project_id"], name: "index_ci_commits_on_gl_project_id", using: :btree
add_index "ci_commits", ["project_id", "committed_at", "id"], name: "index_ci_commits_on_project_id_and_committed_at_and_id", using: :btree
add_index "ci_commits", ["project_id", "committed_at"], name: "index_ci_commits_on_project_id_and_committed_at", using: :btree
add_index "ci_commits", ["project_id", "sha"], name: "index_ci_commits_on_project_id_and_sha", using: :btree
add_index "ci_commits", ["project_id"], name: "index_ci_commits_on_project_id", using: :btree
add_index "ci_commits", ["sha"], name: "index_ci_commits_on_sha", using: :btree
+ add_index "ci_commits", ["status"], name: "index_ci_commits_on_status", using: :btree
create_table "ci_events", force: :cascade do |t|
t.integer "project_id"