summaryrefslogtreecommitdiff
path: root/app/models/internal_id.rb
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2019-01-02 16:50:37 +0100
committerAndreas Brandl <abrandl@gitlab.com>2019-01-29 15:38:40 +0100
commitfede3a0b75e5db720bd4684faca5626d4ef109d2 (patch)
treef1a738e57af08c951839ec388f0dc1473f8d6ac0 /app/models/internal_id.rb
parent13f5f7e64de8016bafc6c897a4dc405250f2f63d (diff)
downloadgitlab-ce-fede3a0b75e5db720bd4684faca5626d4ef109d2.tar.gz
Flush InternalId records after import
After the import has finished, we flush (delete) the InternalId records related to the project at hand. This means we're starting over with tracking correct internal id values, a new record will be created automatically when the next internal id is generated. The GitHub importer assigns iid values by using supplied values from GitHub. We skip tracking internal id values during the import in favor of higher concurrency. Deleting any InternalId records after the import has finished is an extra measure to guarantee consistency. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/54270.
Diffstat (limited to 'app/models/internal_id.rb')
-rw-r--r--app/models/internal_id.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/internal_id.rb b/app/models/internal_id.rb
index 4eb211eff61..e75c6eb2331 100644
--- a/app/models/internal_id.rb
+++ b/app/models/internal_id.rb
@@ -66,6 +66,17 @@ class InternalId < ActiveRecord::Base
InternalIdGenerator.new(subject, scope, usage, init).generate
end
+ # Flushing records is generally safe in a sense that those
+ # records are going to be re-created when needed.
+ #
+ # A filter condition has to be provided to not accidentally flush
+ # records for all projects.
+ def flush_records!(filter)
+ raise ArgumentError, "filter cannot be empty" if filter.blank?
+
+ where(filter).delete_all
+ end
+
def available?
@available_flag ||= ActiveRecord::Migrator.current_version >= REQUIRED_SCHEMA_VERSION # rubocop:disable Gitlab/PredicateMemoization
end