From 403decbbad26bea620125aed34b440a9b6611172 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Mon, 26 Mar 2018 18:58:35 +0200 Subject: [PATCH] Add explicit primary key for ci_builds_metadata table --- app/models/ci/build_metadata.rb | 1 + db/migrate/20180301010859_create_ci_builds_metadata_table.rb | 4 ++-- db/schema.rb | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/ci/build_metadata.rb b/app/models/ci/build_metadata.rb index de5b4170201..96762f8845c 100644 --- a/app/models/ci/build_metadata.rb +++ b/app/models/ci/build_metadata.rb @@ -11,6 +11,7 @@ module Ci belongs_to :build, class_name: 'Ci::Build' belongs_to :project + validates :build, presence: true validates :project, presence: true chronic_duration_attr_reader :timeout_human_readable, :timeout diff --git a/db/migrate/20180301010859_create_ci_builds_metadata_table.rb b/db/migrate/20180301010859_create_ci_builds_metadata_table.rb index 650bf43835d..ce737444092 100644 --- a/db/migrate/20180301010859_create_ci_builds_metadata_table.rb +++ b/db/migrate/20180301010859_create_ci_builds_metadata_table.rb @@ -4,16 +4,16 @@ class CreateCiBuildsMetadataTable < ActiveRecord::Migration DOWNTIME = false def change - create_table :ci_builds_metadata, id: false do |t| + create_table :ci_builds_metadata 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 :build_id, unique: true t.index :project_id end end diff --git a/db/schema.rb b/db/schema.rb index 56541aa4ecd..3d3a4c0ce4a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -329,12 +329,14 @@ ActiveRecord::Schema.define(version: 20180327101207) do add_index "ci_builds", ["updated_at"], name: "index_ci_builds_on_updated_at", using: :btree 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| + create_table "ci_builds_metadata", force: :cascade do |t| + t.integer "build_id", null: false t.integer "project_id", null: false t.integer "timeout" t.integer "timeout_source", default: 1, null: false end + add_index "ci_builds_metadata", ["build_id"], name: "index_ci_builds_metadata_on_build_id", unique: true, using: :btree 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| -- GitLab