summaryrefslogtreecommitdiff
path: root/spec/tasks
diff options
context:
space:
mode:
authorDJ Mountney <david@twkie.net>2019-06-20 07:56:46 -0700
committerDJ Mountney <david@twkie.net>2019-06-25 10:44:40 -0700
commitf4e15535198da1d5a655b6abe0afafac47219ab5 (patch)
tree11c0a29db654aae83d98de903e110f8040c5a3c4 /spec/tasks
parent7a089438fa138934b5dab7bdd575a74a1dfd03c0 (diff)
downloadgitlab-ce-f4e15535198da1d5a655b6abe0afafac47219ab5.tar.gz
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
Diffstat (limited to 'spec/tasks')
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb2
-rw-r--r--spec/tasks/migrate/schema_check_rake_spec.rb27
2 files changed, 28 insertions, 1 deletions
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index f61c03e5cf0..82ebbf9f225 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -31,7 +31,7 @@ describe 'gitlab:db namespace rake task' do
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(RuntimeErrorm, /current database version is too old to be migrated/)
+ 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
diff --git a/spec/tasks/migrate/schema_check_rake_spec.rb b/spec/tasks/migrate/schema_check_rake_spec.rb
new file mode 100644
index 00000000000..50aa95488c6
--- /dev/null
+++ b/spec/tasks/migrate/schema_check_rake_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+require 'rake'
+
+describe 'schema_version_check rake task' do
+ before :all do
+ Rake.application.rake_require 'active_record/railties/databases'
+
+ # empty task as env is already loaded
+ Rake::Task.define_task :environment
+ end
+
+ before 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)
+ end
+
+ it 'raises an error when schema version is too old to migrate' do
+ allow(ActiveRecord::Migrator).to receive(:current_version).and_return(25)
+ expect { run_rake_task('db:migrate') }.to raise_error(RuntimeError, /current database version is too old to be migrated/)
+ end
+
+ def run_rake_task(task_name)
+ Rake::Task[task_name].reenable
+ Rake.application.invoke_task task_name
+ end
+end