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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 16:18:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 16:18:24 +0300
commit0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch)
tree4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/gitlab/database/migration.rb
parent744144d28e3e7fddc117924fef88de5d9674fe4c (diff)
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/gitlab/database/migration.rb')
-rw-r--r--lib/gitlab/database/migration.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/gitlab/database/migration.rb b/lib/gitlab/database/migration.rb
new file mode 100644
index 00000000000..b2248b0f4eb
--- /dev/null
+++ b/lib/gitlab/database/migration.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Database
+ class Migration
+ module LockRetriesConcern
+ extend ActiveSupport::Concern
+
+ class_methods do
+ def enable_lock_retries!
+ @enable_lock_retries = true # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ end
+
+ def enable_lock_retries?
+ @enable_lock_retries
+ end
+ end
+
+ delegate :enable_lock_retries?, to: :class
+ end
+
+ # This implements a simple versioning scheme for migration helpers.
+ #
+ # We need to be able to version helpers, so we can change their behavior without
+ # altering the behavior of already existing migrations in incompatible ways.
+ #
+ # We can continue to change the behavior of helpers without bumping the version here,
+ # *if* the change is backwards-compatible.
+ #
+ # If not, we would typically override the helper method in a new MigrationHelpers::V[0-9]+
+ # class and create a new entry with a bumped version below.
+ #
+ # We use major version bumps to indicate significant changes and minor version bumps
+ # to indicate backwards-compatible or otherwise minor changes (e.g. a Rails version bump).
+ # However, this hasn't been strictly formalized yet.
+ MIGRATION_CLASSES = {
+ 1.0 => Class.new(ActiveRecord::Migration[6.1]) do
+ include LockRetriesConcern
+ include Gitlab::Database::MigrationHelpers::V2
+ end
+ }.freeze
+
+ def self.[](version)
+ MIGRATION_CLASSES[version] || raise(ArgumentError, "Unknown migration version: #{version}")
+ end
+
+ # The current version to be used in new migrations
+ def self.current_version
+ 1.0
+ end
+ end
+ end
+end