diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-11 03:10:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-11 03:10:03 +0300 |
commit | d229251151a3bdeb80a0d8004003700ac3f95893 (patch) | |
tree | e252fc9aecf9452747413c6026139e34557564d3 /app | |
parent | caff5659c981d9b8ed2c086fb35deac9e189b865 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/models/customer_relations/organization.rb | 31 | ||||
-rw-r--r-- | app/models/postgresql/detached_partition.rb | 7 | ||||
-rw-r--r-- | app/workers/all_queues.yml | 9 | ||||
-rw-r--r-- | app/workers/database/drop_detached_partitions_worker.rb | 18 |
4 files changed, 65 insertions, 0 deletions
diff --git a/app/models/customer_relations/organization.rb b/app/models/customer_relations/organization.rb new file mode 100644 index 00000000000..caf1cd68cc5 --- /dev/null +++ b/app/models/customer_relations/organization.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class CustomerRelations::Organization < ApplicationRecord + self.table_name = "customer_relations_organizations" + + belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'group_id' + + before_validation :strip_whitespace! + + enum state: { + inactive: 0, + active: 1 + } + + validates :group, presence: true + validates :name, presence: true + validates :name, uniqueness: { case_sensitive: false, scope: [:group_id] } + validates :name, length: { maximum: 255 } + validates :description, length: { maximum: 1024 } + + def self.find_by_name(group_id, name) + where(group: group_id) + .where('LOWER(name) = LOWER(?)', name) + end + + private + + def strip_whitespace! + name&.strip! + end +end diff --git a/app/models/postgresql/detached_partition.rb b/app/models/postgresql/detached_partition.rb new file mode 100644 index 00000000000..76b299ff9d4 --- /dev/null +++ b/app/models/postgresql/detached_partition.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Postgresql + class DetachedPartition < ApplicationRecord + scope :ready_to_drop, -> { where('drop_after < ?', Time.current) } + end +end diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index 583da304048..fc46b9a6e45 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -247,6 +247,15 @@ :idempotent: true :tags: - :exclude_from_kubernetes +- :name: cronjob:database_drop_detached_partitions + :worker_name: Database::DropDetachedPartitionsWorker + :feature_category: :database + :has_external_dependencies: + :urgency: :low + :resource_boundary: :unknown + :weight: 1 + :idempotent: true + :tags: [] - :name: cronjob:database_partition_management :worker_name: Database::PartitionManagementWorker :feature_category: :database diff --git a/app/workers/database/drop_detached_partitions_worker.rb b/app/workers/database/drop_detached_partitions_worker.rb new file mode 100644 index 00000000000..f9c8ce57a36 --- /dev/null +++ b/app/workers/database/drop_detached_partitions_worker.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Database + class DropDetachedPartitionsWorker + include ApplicationWorker + include CronjobQueue # rubocop:disable Scalability/CronWorkerContext + + feature_category :database + data_consistency :always + idempotent! + + def perform + Gitlab::Database::Partitioning::DetachedPartitionDropper.new.perform + ensure + Gitlab::Database::Partitioning::PartitionMonitoring.new.report_metrics + end + end +end |