summaryrefslogtreecommitdiff
path: root/lib/tasks/gitlab/db.rake
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 15:44:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 15:44:42 +0000
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /lib/tasks/gitlab/db.rake
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
downloadgitlab-ce-4555e1b21c365ed8303ffb7a3325d773c9b8bf31.tar.gz
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'lib/tasks/gitlab/db.rake')
-rw-r--r--lib/tasks/gitlab/db.rake26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake
index 3baf4e7b7c6..bbfdf598e42 100644
--- a/lib/tasks/gitlab/db.rake
+++ b/lib/tasks/gitlab/db.rake
@@ -191,7 +191,7 @@ namespace :gitlab do
ActiveRecord::Base.logger = Logger.new(STDOUT) if Gitlab::Utils.to_boolean(ENV['LOG_QUERIES_TO_CONSOLE'], default: false)
Gitlab::Database::Reindexing.perform(indexes)
- rescue => e
+ rescue StandardError => e
Gitlab::AppLogger.error(e)
raise
end
@@ -217,9 +217,11 @@ namespace :gitlab do
end
desc 'Run migrations with instrumentation'
- task :migration_testing, [:result_file] => :environment do |_, args|
- result_file = args[:result_file] || raise("Please specify result_file argument")
- raise "File exists already, won't overwrite: #{result_file}" if File.exist?(result_file)
+ task migration_testing: :environment do
+ result_dir = Gitlab::Database::Migrations::Instrumentation::RESULT_DIR
+ raise "Directory exists already, won't overwrite: #{result_dir}" if File.exist?(result_dir)
+
+ Dir.mkdir(result_dir)
verbose_was = ActiveRecord::Migration.verbose
ActiveRecord::Migration.verbose = true
@@ -240,7 +242,7 @@ namespace :gitlab do
end
ensure
if instrumentation
- File.open(result_file, 'wb+') do |io|
+ File.open(File.join(result_dir, Gitlab::Database::Migrations::Instrumentation::STATS_FILENAME), 'wb+') do |io|
io << instrumentation.observations.to_json
end
end
@@ -248,5 +250,19 @@ namespace :gitlab do
ActiveRecord::Base.clear_cache!
ActiveRecord::Migration.verbose = verbose_was
end
+
+ desc 'Run all pending batched migrations'
+ task execute_batched_migrations: :environment do
+ Gitlab::Database::BackgroundMigration::BatchedMigration.active.queue_order.each do |migration|
+ Gitlab::AppLogger.info("Executing batched migration #{migration.id} inline")
+ Gitlab::Database::BackgroundMigration::BatchedMigrationRunner.new.run_entire_migration(migration)
+ end
+ end
+
+ # Only for development environments,
+ # we execute pending data migrations inline for convenience.
+ Rake::Task['db:migrate'].enhance do
+ Rake::Task['gitlab:db:execute_batched_migrations'].invoke if Rails.env.development?
+ end
end
end