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 'lib/gitlab/database/postgres_foreign_key.rb')
-rw-r--r--lib/gitlab/database/postgres_foreign_key.rb24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/gitlab/database/postgres_foreign_key.rb b/lib/gitlab/database/postgres_foreign_key.rb
index d3ede45fe86..04ef574a451 100644
--- a/lib/gitlab/database/postgres_foreign_key.rb
+++ b/lib/gitlab/database/postgres_foreign_key.rb
@@ -5,17 +5,23 @@ module Gitlab
class PostgresForeignKey < SharedModel
self.primary_key = :oid
- # These values come from the possible confdeltype values in pg_constraint
- enum on_delete_action: {
+ # These values come from the possible confdeltype / confupdtype values in pg_constraint
+ ACTION_TYPES = {
restrict: 'r',
cascade: 'c',
nullify: 'n',
set_default: 'd',
no_action: 'a'
- }
+ }.freeze
+
+ enum on_delete_action: ACTION_TYPES, _prefix: :on_delete
+
+ enum on_update_action: ACTION_TYPES, _prefix: :on_update
scope :by_referenced_table_identifier, ->(identifier) do
- raise ArgumentError, "Referenced table name is not fully qualified with a schema: #{identifier}" unless identifier =~ /^\w+\.\w+$/
+ unless identifier =~ Database::FULLY_QUALIFIED_IDENTIFIER
+ raise ArgumentError, "Referenced table name is not fully qualified with a schema: #{identifier}"
+ end
where(referenced_table_identifier: identifier)
end
@@ -23,7 +29,9 @@ module Gitlab
scope :by_referenced_table_name, ->(name) { where(referenced_table_name: name) }
scope :by_constrained_table_identifier, ->(identifier) do
- raise ArgumentError, "Constrained table name is not fully qualified with a schema: #{identifier}" unless identifier =~ /^\w+\.\w+$/
+ unless identifier =~ Database::FULLY_QUALIFIED_IDENTIFIER
+ raise ArgumentError, "Constrained table name is not fully qualified with a schema: #{identifier}"
+ end
where(constrained_table_identifier: identifier)
end
@@ -43,6 +51,12 @@ module Gitlab
where(on_delete_action: on_delete)
end
+
+ scope :by_on_update_action, ->(on_update) do
+ raise ArgumentError, "Invalid on_update action #{on_update}" unless on_update_actions.key?(on_update)
+
+ where(on_update_action: on_update)
+ end
end
end
end