diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-10 21:09:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-10 21:09:24 +0000 |
commit | 02c3b2af448be6a5004e8d833cbcbf8e5f185210 (patch) | |
tree | 27359dc5c21a8901c9eb95a0101cb97087b1f4ac /lib/tasks | |
parent | 577bb49691b11bc8ebae3a4966153ed39af60d87 (diff) | |
download | gitlab-ce-02c3b2af448be6a5004e8d833cbcbf8e5f185210.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/db.rake | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index bf0eb6785df..541a4fc62af 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -231,5 +231,37 @@ namespace :gitlab do puts "Found user created projects. Database active" exit 0 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) + + verbose_was, ActiveRecord::Migration.verbose = ActiveRecord::Migration.verbose, true + + ctx = ActiveRecord::Base.connection.migration_context + existing_versions = ctx.get_all_versions.to_set + + pending_migrations = ctx.migrations.reject do |migration| + existing_versions.include?(migration.version) + end + + instrumentation = Gitlab::Database::Migrations::Instrumentation.new + + pending_migrations.each do |migration| + instrumentation.observe(migration.version) do + ActiveRecord::Migrator.new(:up, ctx.migrations, ctx.schema_migration, migration.version).run + end + end + ensure + if instrumentation + File.open(result_file, 'wb+') do |io| + io << instrumentation.observations.to_json + end + end + + ActiveRecord::Base.clear_cache! + ActiveRecord::Migration.verbose = verbose_was + end end end |