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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/analytics/instance_statistics/measurement.rb')
-rw-r--r--app/models/analytics/instance_statistics/measurement.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/models/analytics/instance_statistics/measurement.rb b/app/models/analytics/instance_statistics/measurement.rb
new file mode 100644
index 00000000000..eaaf9e999b3
--- /dev/null
+++ b/app/models/analytics/instance_statistics/measurement.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module Analytics
+ module InstanceStatistics
+ class Measurement < ApplicationRecord
+ enum identifier: {
+ projects: 1,
+ users: 2,
+ issues: 3,
+ merge_requests: 4,
+ groups: 5,
+ pipelines: 6
+ }
+
+ IDENTIFIER_QUERY_MAPPING = {
+ identifiers[:projects] => -> { Project },
+ identifiers[:users] => -> { User },
+ identifiers[:issues] => -> { Issue },
+ identifiers[:merge_requests] => -> { MergeRequest },
+ identifiers[:groups] => -> { Group },
+ identifiers[:pipelines] => -> { Ci::Pipeline }
+ }.freeze
+
+ validates :recorded_at, :identifier, :count, presence: true
+ validates :recorded_at, uniqueness: { scope: :identifier }
+
+ scope :order_by_latest, -> { order(recorded_at: :desc) }
+ scope :with_identifier, -> (identifier) { where(identifier: identifier) }
+ end
+ end
+end