From f4e15535198da1d5a655b6abe0afafac47219ab5 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Thu, 20 Jun 2019 07:56:46 -0700 Subject: Move min schema version check to db:migrate Rather than have it checked only as part of gitlab:db:configure, we will instead have it as a pre-req for every db:migrate command --- lib/gitlab/database.rb | 1 + lib/tasks/gitlab/db.rake | 4 ---- lib/tasks/migrate/schema_check.rake | 11 +++++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 lib/tasks/migrate/schema_check.rake (limited to 'lib') diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index 5e5b79b8e99..2fd9250b3c2 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -14,6 +14,7 @@ module Gitlab # Minimum schema version from which migrations are be supported # Migrations before this version may have been removed MIN_SCHEMA_VERSION = 20190506135400 + MIN_SCHEMA_GITLAB_VERSION = '11.11.0' def self.config ActiveRecord::Base.configurations[Rails.env] diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index 3a371de5bb7..4e7a8adbef6 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -53,10 +53,6 @@ namespace :gitlab do # Check if we have existing db tables # The schema_migrations table will still exist if drop_tables was called if ActiveRecord::Base.connection.tables.count > 1 - if ActiveRecord::Migrator.current_version < Gitlab::Database::MIN_SCHEMA_VERSION - raise "Your current database version is too old to be migrated. Please see https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations" - end - Rake::Task['db:migrate'].invoke else # Add post-migrate paths to ensure we mark all migrations as up diff --git a/lib/tasks/migrate/schema_check.rake b/lib/tasks/migrate/schema_check.rake new file mode 100644 index 00000000000..1f2ed2f439c --- /dev/null +++ b/lib/tasks/migrate/schema_check.rake @@ -0,0 +1,11 @@ +desc 'Configures the database by running migrate, or by loading the schema and seeding if needed' +task schema_version_check: :environment do + if ActiveRecord::Migrator.current_version < Gitlab::Database::MIN_SCHEMA_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] -- cgit v1.2.1