File: build_need.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (39 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module Ci
  class BuildNeed < Ci::ApplicationRecord
    include Ci::Partitionable
    include BulkInsertSafe

    MAX_JOB_NAME_LENGTH = 255

    before_validation :set_project_id, on: :create

    belongs_to :build,
      ->(need) { in_partition(need) },
      class_name: 'Ci::Processable',
      foreign_key: :build_id,
      partition_foreign_key: :partition_id,
      inverse_of: :needs

    partitionable scope: :build

    validates :build, presence: true
    validates :name, presence: true, length: { maximum: MAX_JOB_NAME_LENGTH }
    validates :optional, inclusion: { in: [true, false] }
    validates :project_id, presence: true, on: :create

    scope :scoped_build, -> {
      where(arel_table[:build_id].eq(Ci::Build.arel_table[:id]))
      .where(arel_table[:partition_id].eq(Ci::Build.arel_table[:partition_id]))
    }
    scope :artifacts, -> { where(artifacts: true) }

    # TODO: This is temporary code to assist the backfilling of records for this epic: https://gitlab.com/groups/gitlab-org/-/epics/12323
    # To be removed in 17.7: https://gitlab.com/gitlab-org/gitlab/-/issues/488163
    #
    def set_project_id
      self.project_id ||= build&.project_id
    end
  end
end