summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2018-03-21 01:20:15 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2018-03-28 13:58:34 +0200
commita1cd3390e550c0008e83146e8627fdee3f58e422 (patch)
tree348413849dac37229d4ec9d59834440844481e3c
parentafcc57abfdcb11001803655f938187cbdc96b67c (diff)
downloadgitlab-ce-a1cd3390e550c0008e83146e8627fdee3f58e422.tar.gz
Add project_id column to Ci::BuildMetadata
-rw-r--r--app/models/ci/build_metadata.rb11
-rw-r--r--db/migrate/20180301010859_create_ci_builds_metadata_table.rb4
-rw-r--r--db/schema.rb4
3 files changed, 19 insertions, 0 deletions
diff --git a/app/models/ci/build_metadata.rb b/app/models/ci/build_metadata.rb
index 424b6da1014..c221f43384b 100644
--- a/app/models/ci/build_metadata.rb
+++ b/app/models/ci/build_metadata.rb
@@ -9,9 +9,12 @@ module Ci
self.table_name = 'ci_builds_metadata'
belongs_to :build, class_name: 'Ci::Build'
+ belongs_to :project
chronic_duration_attr_reader :timeout_human_readable, :timeout
+ after_initialize :set_project_id
+
enum timeout_source: {
unknown_timeout_source: 1,
project_timeout_source: 2,
@@ -27,5 +30,13 @@ module Ci
update_attributes(timeout: timeout, timeout_source: timeout_source)
end
+
+ private
+
+ def set_project_id
+ return unless self.project_id.nil?
+
+ self.project_id = build&.project&.id
+ end
end
end
diff --git a/db/migrate/20180301010859_create_ci_builds_metadata_table.rb b/db/migrate/20180301010859_create_ci_builds_metadata_table.rb
index 72c204026d8..650bf43835d 100644
--- a/db/migrate/20180301010859_create_ci_builds_metadata_table.rb
+++ b/db/migrate/20180301010859_create_ci_builds_metadata_table.rb
@@ -6,11 +6,15 @@ class CreateCiBuildsMetadataTable < ActiveRecord::Migration
def change
create_table :ci_builds_metadata, id: false do |t|
t.integer :build_id, null: false
+ t.integer :project_id, null: false
t.integer :timeout
t.integer :timeout_source, null: false, default: 1
t.primary_key :build_id
t.foreign_key :ci_builds, column: :build_id, on_delete: :cascade
+ t.foreign_key :projects, column: :project_id, on_delete: :cascade
+
+ t.index :project_id
end
end
end
diff --git a/db/schema.rb b/db/schema.rb
index a14823dfa15..56541aa4ecd 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -330,10 +330,13 @@ ActiveRecord::Schema.define(version: 20180327101207) do
add_index "ci_builds", ["user_id"], name: "index_ci_builds_on_user_id", using: :btree
create_table "ci_builds_metadata", primary_key: "build_id", force: :cascade do |t|
+ t.integer "project_id", null: false
t.integer "timeout"
t.integer "timeout_source", default: 1, null: false
end
+ add_index "ci_builds_metadata", ["project_id"], name: "index_ci_builds_metadata_on_project_id", using: :btree
+
create_table "ci_group_variables", force: :cascade do |t|
t.string "key", null: false
t.text "value"
@@ -2035,6 +2038,7 @@ ActiveRecord::Schema.define(version: 20180327101207) do
add_foreign_key "ci_builds", "ci_stages", column: "stage_id", name: "fk_3a9eaa254d", on_delete: :cascade
add_foreign_key "ci_builds", "projects", name: "fk_befce0568a", on_delete: :cascade
add_foreign_key "ci_builds_metadata", "ci_builds", column: "build_id", on_delete: :cascade
+ add_foreign_key "ci_builds_metadata", "projects", on_delete: :cascade
add_foreign_key "ci_group_variables", "namespaces", column: "group_id", name: "fk_33ae4d58d8", on_delete: :cascade
add_foreign_key "ci_job_artifacts", "ci_builds", column: "job_id", on_delete: :cascade
add_foreign_key "ci_job_artifacts", "projects", on_delete: :cascade