Welcome to mirror list, hosted at ThFree Co, Russian Federation.

models.rb « support « spec « activerecord-gitlab « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0017656ea814d87fef9e81d73e06abdcc5a88e3 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

class PartitionedRecord < ActiveRecord::Base
  self.abstract_class = true

  def self.use_partition_id_filter?
    true
  end

  alias_method :reset, :reload
end

class Project < ActiveRecord::Base
  has_many :pipelines
end

class Pipeline < PartitionedRecord
  belongs_to :project
  query_constraints :id, :partition_id

  has_many :jobs,
    ->(pipeline) { where(partition_id: pipeline.partition_id) },
    partition_foreign_key: :partition_id,
    dependent: :destroy
end

class Job < PartitionedRecord
  query_constraints :id, :partition_id

  belongs_to :pipeline,
    ->(build) { where(partition_id: build.partition_id) },
    partition_foreign_key: :partition_id

  has_one :metadata,
    ->(build) { where(partition_id: build.partition_id) },
    foreign_key: :job_id,
    partition_foreign_key: :partition_id,
    inverse_of: :job,
    autosave: true

  accepts_nested_attributes_for :metadata
end

class Metadata < PartitionedRecord
  self.table_name = :metadata
  query_constraints :id, :partition_id

  belongs_to :job,
    ->(metadata) { where(partition_id: metadata.partition_id) }
end