2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
2021-11-11 11:23:49 +05:30
|
|
|
class PostgresPartition < SharedModel
|
2021-01-29 00:20:46 +05:30
|
|
|
self.primary_key = :identifier
|
|
|
|
|
|
|
|
belongs_to :postgres_partitioned_table, foreign_key: 'parent_identifier', primary_key: 'identifier'
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
scope :for_identifier, ->(identifier) do
|
2021-01-29 00:20:46 +05:30
|
|
|
raise ArgumentError, "Partition name is not fully qualified with a schema: #{identifier}" unless identifier =~ /^\w+\.\w+$/
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
where(primary_key => identifier)
|
|
|
|
end
|
|
|
|
|
|
|
|
scope :by_identifier, ->(identifier) do
|
|
|
|
for_identifier(identifier).first!
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
scope :for_parent_table, ->(name) { where("parent_identifier = concat(current_schema(), '.', ?)", name).order(:name) }
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|