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

postgres_async_index.rb « async_indexes « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f5f39613ed9ef6741d18971381d6373ae0e3fe5 (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
# frozen_string_literal: true

module Gitlab
  module Database
    module AsyncIndexes
      class PostgresAsyncIndex < SharedModel
        include QueueErrorHandlingConcern

        self.table_name = 'postgres_async_indexes'

        MAX_IDENTIFIER_LENGTH = Gitlab::Database::MigrationHelpers::MAX_IDENTIFIER_NAME_LENGTH
        MAX_DEFINITION_LENGTH = 2048

        validates :name, presence: true, length: { maximum: MAX_IDENTIFIER_LENGTH }
        validates :table_name, presence: true, length: { maximum: MAX_IDENTIFIER_LENGTH }
        validates :definition, presence: true, length: { maximum: MAX_DEFINITION_LENGTH }

        scope :to_create, -> { where("definition ILIKE 'CREATE%'") }
        scope :to_drop, -> { where("definition ILIKE 'DROP%'") }
        scope :ordered, -> { order(attempts: :asc, id: :asc) }

        def to_s
          definition
        end
      end
    end
  end
end