summaryrefslogtreecommitdiff
path: root/spec/tasks
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 /spec/tasks
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.
Diffstat (limited to 'spec/tasks')
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb7
-rw-r--r--spec/tasks/migrate/schema_check_rake_spec.rb21
2 files changed, 21 insertions, 7 deletions
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