Commit 9d971b24 authored by Thong Kuah's avatar Thong Kuah

Merge branch '336426-inherit-ci-models-from-ci-application-record' into 'master'

Inherit CI models from Ci::ApplicationRecord [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!66396
parents 825247ab 8adb61e1
# frozen_string_literal: true
module Ci
class ApplicationRecord < ::ApplicationRecord
self.abstract_class = true
def self.table_name_prefix
'ci_'
end
def self.model_name
@model_name ||= ActiveModel::Name.new(self, nil, self.name.demodulize)
end
end
end
......@@ -3,10 +3,9 @@
module Ci
# The purpose of this class is to store Build related data that can be disposed.
# Data that should be persisted forever, should be stored with Ci::Build model.
class BuildMetadata < ApplicationRecord
class BuildMetadata < Ci::ApplicationRecord
BuildTimeout = Struct.new(:value, :source)
extend Gitlab::Ci::Model
include Presentable
include ChronicDurationAttribute
include Gitlab::Utils::StrongMemoize
......
# frozen_string_literal: true
module Ci
class BuildNeed < ApplicationRecord
extend Gitlab::Ci::Model
class BuildNeed < Ci::ApplicationRecord
include BulkInsertSafe
include IgnorableColumns
......
# frozen_string_literal: true
class Ci::BuildPendingState < ApplicationRecord
extend Gitlab::Ci::Model
class Ci::BuildPendingState < Ci::ApplicationRecord
belongs_to :build, class_name: 'Ci::Build', foreign_key: :build_id
enum state: Ci::Stage.statuses
......
# frozen_string_literal: true
module Ci
class BuildReportResult < ApplicationRecord
extend Gitlab::Ci::Model
class BuildReportResult < Ci::ApplicationRecord
self.primary_key = :build_id
belongs_to :build, class_name: "Ci::Build", inverse_of: :report_results
......
......@@ -3,8 +3,7 @@
module Ci
# The purpose of this class is to store Build related runner session.
# Data will be removed after transitioning from running to any state.
class BuildRunnerSession < ApplicationRecord
extend Gitlab::Ci::Model
class BuildRunnerSession < Ci::ApplicationRecord
include IgnorableColumns
ignore_columns :build_id_convert_to_bigint, remove_with: '14.1', remove_after: '2021-07-22'
......
# frozen_string_literal: true
module Ci
class BuildTraceChunk < ApplicationRecord
extend ::Gitlab::Ci::Model
class BuildTraceChunk < Ci::ApplicationRecord
include ::Comparable
include ::FastDestroyAll
include ::Checksummable
......
......@@ -7,7 +7,7 @@ module Ci
# This class is part of a migration to move all CI classes to a new separate database.
# Initially we are only going to be moving the `Ci::InstanceVariable` model and it will be duplicated in the main and CI tables
# Do not extend this class in any other models.
class BaseModel < ::ApplicationRecord
class CiDatabaseRecord < Ci::ApplicationRecord
self.abstract_class = true
if Gitlab::Database.has_config?(:ci)
......
# frozen_string_literal: true
module Ci
class DailyBuildGroupReportResult < ApplicationRecord
extend Gitlab::Ci::Model
class DailyBuildGroupReportResult < Ci::ApplicationRecord
PARAM_TYPES = %w[coverage].freeze
belongs_to :last_pipeline, class_name: 'Ci::Pipeline', foreign_key: :last_pipeline_id
......
# frozen_string_literal: true
module Ci
class DeletedObject < ApplicationRecord
extend Gitlab::Ci::Model
class DeletedObject < Ci::ApplicationRecord
mount_uploader :file, DeletedObjectUploader
scope :ready_for_destruction, ->(limit) do
......
# frozen_string_literal: true
module Ci
class FreezePeriod < ApplicationRecord
class FreezePeriod < Ci::ApplicationRecord
include StripAttribute
self.table_name = 'ci_freeze_periods'
include Ci::NamespacedModelName
default_scope { order(created_at: :asc) } # rubocop:disable Cop/DefaultScope
......
# frozen_string_literal: true
module Ci
class GroupVariable < ApplicationRecord
extend Gitlab::Ci::Model
class GroupVariable < Ci::ApplicationRecord
include Ci::HasVariable
include Presentable
include Ci::Maskable
......
# frozen_string_literal: true
module Ci
class InstanceVariable < ::Ci::BaseModel
extend Gitlab::Ci::Model
class InstanceVariable < Ci::CiDatabaseRecord
extend Gitlab::ProcessMemoryCache::Helper
include Ci::NewHasVariable
include Ci::Maskable
......
# frozen_string_literal: true
module Ci
class JobArtifact < ApplicationRecord
class JobArtifact < Ci::ApplicationRecord
include AfterCommitQueue
include ObjectStorage::BackgroundMove
include UpdateProjectStatistics
......@@ -10,7 +10,6 @@ module Ci
include Artifactable
include FileStoreMounter
include EachBatch
extend Gitlab::Ci::Model
TEST_REPORT_FILE_TYPES = %w[junit].freeze
COVERAGE_REPORT_FILE_TYPES = %w[cobertura].freeze
......
# frozen_string_literal: true
module Ci
class JobVariable < ApplicationRecord
extend Gitlab::Ci::Model
class JobVariable < Ci::ApplicationRecord
include Ci::NewHasVariable
include BulkInsertSafe
......
# frozen_string_literal: true
module Ci
class PendingBuild < ApplicationRecord
extend Gitlab::Ci::Model
class PendingBuild < Ci::ApplicationRecord
belongs_to :project
belongs_to :build, class_name: 'Ci::Build'
......
# frozen_string_literal: true
module Ci
class Pipeline < ApplicationRecord
extend Gitlab::Ci::Model
class Pipeline < Ci::ApplicationRecord
include Ci::HasStatus
include Importable
include AfterCommitQueue
......
......@@ -3,8 +3,7 @@
# This class is being used to persist additional artifacts after a pipeline completes, which is a great place to cache a computed result in object storage
module Ci
class PipelineArtifact < ApplicationRecord
extend Gitlab::Ci::Model
class PipelineArtifact < Ci::ApplicationRecord
include UpdateProjectStatistics
include Artifactable
include FileStoreMounter
......
# frozen_string_literal: true
module Ci
class PipelineChatData < ApplicationRecord
class PipelineChatData < Ci::ApplicationRecord
include Ci::NamespacedModelName
self.table_name = 'ci_pipeline_chat_data'
belongs_to :chat_name
......
# frozen_string_literal: true
module Ci
class PipelineConfig < ApplicationRecord
extend Gitlab::Ci::Model
class PipelineConfig < Ci::ApplicationRecord
self.table_name = 'ci_pipelines_config'
self.primary_key = :pipeline_id
......
# frozen_string_literal: true
module Ci
class PipelineMessage < ApplicationRecord
extend Gitlab::Ci::Model
class PipelineMessage < Ci::ApplicationRecord
MAX_CONTENT_LENGTH = 10_000
belongs_to :pipeline
......
# frozen_string_literal: true
module Ci
class PipelineSchedule < ApplicationRecord
extend Gitlab::Ci::Model
class PipelineSchedule < Ci::ApplicationRecord
extend ::Gitlab::Utils::Override
include Importable
include StripAttribute
......
# frozen_string_literal: true
module Ci
class PipelineScheduleVariable < ApplicationRecord
extend Gitlab::Ci::Model
class PipelineScheduleVariable < Ci::ApplicationRecord
include Ci::HasVariable
belongs_to :pipeline_schedule
......
# frozen_string_literal: true
module Ci
class PipelineVariable < ApplicationRecord
extend Gitlab::Ci::Model
class PipelineVariable < Ci::ApplicationRecord
include Ci::HasVariable
belongs_to :pipeline
......
# frozen_string_literal: true
module Ci
class Ref < ApplicationRecord
extend Gitlab::Ci::Model
class Ref < Ci::ApplicationRecord
include AfterCommitQueue
include Gitlab::OptimisticLocking
......
# frozen_string_literal: true
module Ci
class Resource < ApplicationRecord
extend Gitlab::Ci::Model
class Resource < Ci::ApplicationRecord
belongs_to :resource_group, class_name: 'Ci::ResourceGroup', inverse_of: :resources
belongs_to :processable, class_name: 'Ci::Processable', foreign_key: 'build_id', inverse_of: :resource
......
# frozen_string_literal: true
module Ci
class ResourceGroup < ApplicationRecord
extend Gitlab::Ci::Model
class ResourceGroup < Ci::ApplicationRecord
belongs_to :project, inverse_of: :resource_groups
has_many :resources, class_name: 'Ci::Resource', inverse_of: :resource_group
......
# frozen_string_literal: true
module Ci
class Runner < ApplicationRecord
extend Gitlab::Ci::Model
class Runner < Ci::ApplicationRecord
include Gitlab::SQL::Pattern
include RedisCacheable
include ChronicDurationAttribute
......
# frozen_string_literal: true
module Ci
class RunnerNamespace < ApplicationRecord
extend Gitlab::Ci::Model
class RunnerNamespace < Ci::ApplicationRecord
include Limitable
self.limit_name = 'ci_registered_group_runners'
......
# frozen_string_literal: true
module Ci
class RunnerProject < ApplicationRecord
extend Gitlab::Ci::Model
class RunnerProject < Ci::ApplicationRecord
include Limitable
self.limit_name = 'ci_registered_project_runners'
......
# frozen_string_literal: true
module Ci
class RunningBuild < ApplicationRecord
extend Gitlab::Ci::Model
class RunningBuild < Ci::ApplicationRecord
belongs_to :project
belongs_to :build, class_name: 'Ci::Build'
belongs_to :runner, class_name: 'Ci::Runner'
......
......@@ -2,7 +2,9 @@
module Ci
module Sources
class Pipeline < ApplicationRecord
class Pipeline < Ci::ApplicationRecord
include Ci::NamespacedModelName
self.table_name = "ci_sources_pipelines"
belongs_to :project, class_name: "Project"
......
# frozen_string_literal: true
module Ci
class Stage < ApplicationRecord
extend Gitlab::Ci::Model
class Stage < Ci::ApplicationRecord
include Importable
include Ci::HasStatus
include Gitlab::OptimisticLocking
......
# frozen_string_literal: true
module Ci
class Trigger < ApplicationRecord
extend Gitlab::Ci::Model
class Trigger < Ci::ApplicationRecord
include Presentable
belongs_to :project
......
# frozen_string_literal: true
module Ci
class TriggerRequest < ApplicationRecord
extend Gitlab::Ci::Model
class TriggerRequest < Ci::ApplicationRecord
belongs_to :trigger
belongs_to :pipeline, foreign_key: :commit_id
has_many :builds
......
# frozen_string_literal: true
module Ci
class UnitTest < ApplicationRecord
extend Gitlab::Ci::Model
class UnitTest < Ci::ApplicationRecord
MAX_NAME_SIZE = 255
MAX_SUITE_NAME_SIZE = 255
......
# frozen_string_literal: true
module Ci
class UnitTestFailure < ApplicationRecord
extend Gitlab::Ci::Model
class UnitTestFailure < Ci::ApplicationRecord
REPORT_WINDOW = 14.days
validates :unit_test, :build, :failed_at, presence: true
......
# frozen_string_literal: true
module Ci
class Variable < ApplicationRecord
extend Gitlab::Ci::Model
class Variable < Ci::ApplicationRecord
include Ci::HasVariable
include Presentable
include Ci::Maskable
......
# frozen_string_literal: true
class CiPlatformMetric < ApplicationRecord
class CiPlatformMetric < Ci::ApplicationRecord
include BulkInsertSafe
self.table_name = 'ci_platform_metrics'
PLATFORM_TARGET_MAX_LENGTH = 255
validates :recorded_at, presence: true
......
# frozen_string_literal: true
class CommitStatus < ApplicationRecord
class CommitStatus < Ci::ApplicationRecord
include Ci::HasStatus
include Importable
include AfterCommitQueue
......
# frozen_string_literal: true
module Gitlab
module Ci
module Model
def table_name_prefix
"ci_"
end
module Ci
module NamespacedModelName
extend ActiveSupport::Concern
class_methods do
def model_name
@model_name ||= ActiveModel::Name.new(self, nil, self.name.demodulize)
@model_name ||= ActiveModel::Name.new(self, Ci)
end
end
end
......
......@@ -92,7 +92,7 @@ test: &test
### Migrations
Any migrations that affect `Ci::BaseModel` models
Any migrations that affect `Ci::CiDatabaseRecord` models
and their tables must be placed in two directories for now:
- `db/migrate`
......
......@@ -7,7 +7,9 @@
# purchase via CustomersDot/Zuora
module Ci
module Minutes
class AdditionalPack < ApplicationRecord
class AdditionalPack < Ci::ApplicationRecord
include Ci::NamespacedModelName
self.table_name = 'ci_minutes_additional_packs'
belongs_to :namespace
......
......@@ -4,8 +4,8 @@ module Ci
module Minutes
# Track usage of Shared Runners minutes at root namespace level.
# This class ensures that we keep 1 record per namespace per month.
class NamespaceMonthlyUsage < ApplicationRecord
self.table_name = "ci_namespace_monthly_usages"
class NamespaceMonthlyUsage < Ci::ApplicationRecord
include Ci::NamespacedModelName
belongs_to :namespace
......
......@@ -4,8 +4,8 @@ module Ci
module Minutes
# Track usage of Shared Runners minutes at root project level.
# This class ensures that we keep 1 record per project per month.
class ProjectMonthlyUsage < ApplicationRecord
self.table_name = "ci_project_monthly_usages"
class ProjectMonthlyUsage < Ci::ApplicationRecord
include Ci::NamespacedModelName
belongs_to :project
......
......@@ -2,7 +2,9 @@
module Ci
module Sources
class Project < ApplicationRecord
class Project < Ci::ApplicationRecord
include Ci::NamespacedModelName
self.table_name = "ci_sources_projects"
belongs_to :pipeline, class_name: "Ci::Pipeline", optional: false
......
......@@ -2,7 +2,8 @@
module Ci
module Subscriptions
class Project < ApplicationRecord
class Project < Ci::ApplicationRecord
include Ci::NamespacedModelName
include ::Limitable
self.table_name = 'ci_subscriptions_projects'
......
......@@ -13,7 +13,7 @@ RSpec.describe Gitlab::Database::SchemaMigrations::Context do
end
context 'multiple databases' do
let(:connection) { Ci::BaseModel.connection }
let(:connection) { Ci::CiDatabaseRecord.connection }
it 'returns a directory path that is database specific' do
skip_if_multiple_databases_not_setup
......
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