2021-09-01 18:08:49 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
|
|
|
class Migration
|
2021-09-08 15:09:10 +00:00
|
|
|
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
|
|
|
|
|
2021-09-01 18:08:49 +00:00
|
|
|
# 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.
|
2022-03-21 03:08:23 +00:00
|
|
|
|
|
|
|
class V1_0 < ActiveRecord::Migration[6.1] # rubocop:disable Naming/ClassAndModuleCamelCase
|
|
|
|
include LockRetriesConcern
|
|
|
|
include Gitlab::Database::MigrationHelpers::V2
|
2022-04-13 18:08:33 +00:00
|
|
|
|
|
|
|
# When running migrations, the `db:migrate` switches connection of
|
|
|
|
# ActiveRecord::Base depending where the migration runs.
|
|
|
|
# This helper class is provided to avoid confusion using `ActiveRecord::Base`
|
|
|
|
class MigrationRecord < ActiveRecord::Base
|
2022-04-21 12:10:16 +00:00
|
|
|
self.abstract_class = true # Prevent STI behavior
|
2022-04-13 18:08:33 +00:00
|
|
|
end
|
2022-03-21 03:08:23 +00:00
|
|
|
end
|
2021-09-01 18:08:49 +00:00
|
|
|
|
2022-04-25 15:08:44 +00:00
|
|
|
class V2_0 < V1_0 # rubocop:disable Naming/ClassAndModuleCamelCase
|
|
|
|
include Gitlab::Database::MigrationHelpers::RestrictGitlabSchema
|
|
|
|
end
|
|
|
|
|
2021-09-01 18:08:49 +00:00
|
|
|
def self.[](version)
|
2022-03-21 03:08:23 +00:00
|
|
|
version = version.to_s
|
|
|
|
name = "V#{version.tr('.', '_')}"
|
|
|
|
raise ArgumentError, "Unknown migration version: #{version}" unless const_defined?(name, false)
|
|
|
|
|
|
|
|
const_get(name, false)
|
2021-09-01 18:08:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# The current version to be used in new migrations
|
|
|
|
def self.current_version
|
2022-04-13 18:08:33 +00:00
|
|
|
2.0
|
2021-09-01 18:08:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|