Commit a1cd3390 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Add project_id column to Ci::BuildMetadata

parent afcc57ab
......@@ -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
......@@ -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
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment