2021-07-27 08:10:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
2021-09-16 14:11:32 -04:00
|
|
|
class PostgresForeignKey < SharedModel
|
2021-07-27 08:10:54 -04:00
|
|
|
self.primary_key = :oid
|
|
|
|
|
|
|
|
scope :by_referenced_table_identifier, ->(identifier) do
|
|
|
|
raise ArgumentError, "Referenced table name is not fully qualified with a schema: #{identifier}" unless identifier =~ /^\w+\.\w+$/
|
|
|
|
|
|
|
|
where(referenced_table_identifier: identifier)
|
|
|
|
end
|
2021-10-29 17:13:01 -04:00
|
|
|
|
|
|
|
scope :by_constrained_table_identifier, ->(identifier) do
|
|
|
|
raise ArgumentError, "Constrained table name is not fully qualified with a schema: #{identifier}" unless identifier =~ /^\w+\.\w+$/
|
|
|
|
|
|
|
|
where(constrained_table_identifier: identifier)
|
|
|
|
end
|
2021-07-27 08:10:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|