2020-10-22 14:09:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
2021-09-16 14:11:32 -04:00
|
|
|
class PostgresPartitionedTable < SharedModel
|
2020-10-22 14:09:01 -04:00
|
|
|
DYNAMIC_PARTITION_STRATEGIES = %w[range list].freeze
|
|
|
|
|
|
|
|
self.primary_key = :identifier
|
|
|
|
|
2020-10-23 11:08:42 -04:00
|
|
|
has_many :postgres_partitions, foreign_key: 'parent_identifier', primary_key: 'identifier'
|
|
|
|
|
2020-10-22 14:09:01 -04:00
|
|
|
scope :by_identifier, ->(identifier) do
|
|
|
|
raise ArgumentError, "Table name is not fully qualified with a schema: #{identifier}" unless identifier =~ /^\w+\.\w+$/
|
|
|
|
|
|
|
|
find(identifier)
|
|
|
|
end
|
|
|
|
|
2020-11-03 19:09:12 -05:00
|
|
|
def self.find_by_name_in_current_schema(name)
|
|
|
|
find_by("identifier = concat(current_schema(), '.', ?)", name)
|
|
|
|
end
|
|
|
|
|
2020-10-22 14:09:01 -04:00
|
|
|
def dynamic?
|
|
|
|
DYNAMIC_PARTITION_STRATEGIES.include?(strategy)
|
|
|
|
end
|
|
|
|
|
|
|
|
def static?
|
|
|
|
!dynamic?
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|