File: schema_check.rake

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (24 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

# Configures the database by running migrate, or by loading the schema and seeding if needed
task schema_version_check: :environment do
  next if ENV['SKIP_SCHEMA_VERSION_CHECK']

  schema_version = ActiveRecord::Migrator.current_version

  minimum_migration_version = Gitlab::Database.read_minimum_migration_version

  raise 'Unable to find any migration files in db/migrate.' if minimum_migration_version.nil?

  # Ensure migrations are being run from a supported schema version
  # A schema verison of 0 is a fresh db, and should be safe to run migrations
  # But a database with existing migrations less than our min version is not
  if schema_version > 0 && schema_version < minimum_migration_version
    raise "Your current database version is too old to be migrated. " \
          "You should upgrade to GitLab #{Gitlab::Database.min_schema_gitlab_version} before moving to this version. " \
          "Please see https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations"
  end
end

# Ensure the check is a pre-requisite when running db:migrate
Rake::Task["db:migrate"].enhance [:schema_version_check]