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:
authorAndreas Brandl <abrandl@gitlab.com>2018-07-27 15:39:48 +0300
committerAndreas Brandl <abrandl@gitlab.com>2018-07-30 12:51:43 +0300
commit90778e5d2752d4c10a536127d6ce75c32951b8c6 (patch)
treeecdce0141ccb2293724b6cb0b82531cbb5575f6a /app/models
parent2ca8219a20f16636b7a0ffa899a1a04ab8e84782 (diff)
Require has_internal_id to pass a init block.
This is useful since the current scheme allows us to freely delete any records in internal_ids. If the record is not there, it will get rebuild using the init block. We require passing in 'init for the time being and as long as its not expensive to do so. This makes the scheme a bit more robust. If at some point, this is expensive - we may choose to make this optional while losing the ability to recalculate the value on the fly. Closes #49609.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/atomic_internal_id.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/app/models/concerns/atomic_internal_id.rb b/app/models/concerns/atomic_internal_id.rb
index 164c704260e..4fef615e6e3 100644
--- a/app/models/concerns/atomic_internal_id.rb
+++ b/app/models/concerns/atomic_internal_id.rb
@@ -26,6 +26,10 @@ module AtomicInternalId
module ClassMethods
def has_internal_id(column, scope:, init:, presence: true) # rubocop:disable Naming/PredicateName
+ # We require init here to retain the ability to recalculate in the absence of a
+ # InternaLId record (we may delete records in `internal_ids` for example).
+ raise "has_internal_id requires a init block, none given." unless init
+
before_validation :"ensure_#{scope}_#{column}!", on: :create
validates column, presence: presence