summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDJ Mountney <david@twkie.net>2019-06-20 08:50:46 -0700
committerDJ Mountney <david@twkie.net>2019-06-25 10:44:40 -0700
commite448124fab59ce562fac5db9d9919d24ac95fba7 (patch)
tree8a92cf78d02d0b967668a9730b02d5795bdb2688
parentf4232d848eebcdc709ccec9c2004753accb3f3b5 (diff)
downloadgitlab-ce-e448124fab59ce562fac5db9d9919d24ac95fba7.tar.gz
Add an flag for skipping the schema version check
If you chose to use the rollback migration feature on your current version for example, you should still have a way to migrate, being that you are still on a supported migration path.
-rw-r--r--.gitlab/ci/rails.gitlab-ci.yml2
-rw-r--r--changelogs/unreleased/check-min-schema-migrate.yml2
-rw-r--r--lib/tasks/migrate/schema_check.rake2
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb7
-rw-r--r--spec/tasks/migrate/schema_check_rake_spec.rb21
5 files changed, 25 insertions, 9 deletions
diff --git a/.gitlab/ci/rails.gitlab-ci.yml b/.gitlab/ci/rails.gitlab-ci.yml
index 529a0de696b..2cd40f84ec7 100644
--- a/.gitlab/ci/rails.gitlab-ci.yml
+++ b/.gitlab/ci/rails.gitlab-ci.yml
@@ -244,7 +244,7 @@ migration:path-pg:
extends: .dedicated-no-docs-and-no-qa-pull-cache-job
script:
- bundle exec rake db:migrate VERSION=20170523121229
- - bundle exec rake db:migrate
+ - bundle exec rake db:migrate SKIP_SCHEMA_VERSION_CHECK=true
dependencies:
- setup-test-env
diff --git a/changelogs/unreleased/check-min-schema-migrate.yml b/changelogs/unreleased/check-min-schema-migrate.yml
index 68833733bb8..d0f4ae1f5d7 100644
--- a/changelogs/unreleased/check-min-schema-migrate.yml
+++ b/changelogs/unreleased/check-min-schema-migrate.yml
@@ -1,5 +1,5 @@
---
-title: Added a min schema version check to gitlab:db:configure
+title: Added a min schema version check to db:migrate
merge_request: 29882
author:
type: added
diff --git a/lib/tasks/migrate/schema_check.rake b/lib/tasks/migrate/schema_check.rake
index e8505e576a4..d78599a3759 100644
--- a/lib/tasks/migrate/schema_check.rake
+++ b/lib/tasks/migrate/schema_check.rake
@@ -1,5 +1,7 @@
desc '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
# Ensure migrations are being run from a supported schema version
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index 82ebbf9f225..5818892d56a 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -16,7 +16,6 @@ describe 'gitlab:db namespace rake task' do
allow(Rake::Task['db:migrate']).to receive(:invoke).and_return(true)
allow(Rake::Task['db:schema:load']).to receive(:invoke).and_return(true)
allow(Rake::Task['db:seed_fu']).to receive(:invoke).and_return(true)
- allow(ActiveRecord::Migrator).to receive(:current_version).and_return(Gitlab::Database::MIN_SCHEMA_VERSION)
end
describe 'configure' do
@@ -28,12 +27,6 @@ describe 'gitlab:db namespace rake task' do
expect { run_rake_task('gitlab:db:configure') }.not_to raise_error
end
- it 'raises an when schema has been loaded, but version is too old to migrate' do
- allow(ActiveRecord::Base.connection).to receive(:tables).and_return(%w[table1 table2])
- allow(ActiveRecord::Migrator).to receive(:current_version).and_return(25)
- expect { run_rake_task('gitlab:db:configure') }.to raise_error(RuntimeError, /current database version is too old to be migrated/)
- end
-
it 'invokes db:shema:load and db:seed_fu when schema is not loaded' do
allow(ActiveRecord::Base.connection).to receive(:tables).and_return([])
expect(Rake::Task['db:schema:load']).to receive(:invoke)
diff --git a/spec/tasks/migrate/schema_check_rake_spec.rb b/spec/tasks/migrate/schema_check_rake_spec.rb
index 50aa95488c6..6e308bc603c 100644
--- a/spec/tasks/migrate/schema_check_rake_spec.rb
+++ b/spec/tasks/migrate/schema_check_rake_spec.rb
@@ -2,8 +2,11 @@ require 'spec_helper'
require 'rake'
describe 'schema_version_check rake task' do
+ include StubENV
+
before :all do
Rake.application.rake_require 'active_record/railties/databases'
+ Rake.application.rake_require 'tasks/migrate/schema_check'
# empty task as env is already loaded
Rake::Task.define_task :environment
@@ -13,6 +16,13 @@ describe 'schema_version_check rake task' do
# Stub out db tasks
allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:migrate).and_return(true)
allow(ActiveRecord::Migrator).to receive(:current_version).and_return(Gitlab::Database::MIN_SCHEMA_VERSION)
+
+ # Ensure our check can re-run each time
+ Rake::Task[:schema_version_check].reenable
+ end
+
+ it 'allows migrations on databases meeting the min schema version requirement' do
+ expect { run_rake_task('db:migrate') }.not_to raise_error
end
it 'raises an error when schema version is too old to migrate' do
@@ -20,6 +30,17 @@ describe 'schema_version_check rake task' do
expect { run_rake_task('db:migrate') }.to raise_error(RuntimeError, /current database version is too old to be migrated/)
end
+ it 'skips running validation when passed the skip env variable' do
+ stub_env('SKIP_SCHEMA_VERSION_CHECK', 'true')
+ allow(ActiveRecord::Migrator).to receive(:current_version).and_return(25)
+ expect { run_rake_task('db:migrate') }.not_to raise_error
+ end
+
+ it 'allows migrations on fresh databases' do
+ allow(ActiveRecord::Migrator).to receive(:current_version).and_return(0)
+ expect { run_rake_task('db:migrate') }.not_to raise_error
+ end
+
def run_rake_task(task_name)
Rake::Task[task_name].reenable
Rake.application.invoke_task task_name