debian-mirror-gitlab/app/controllers/admin/background_migrations_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2 KiB
Ruby
Raw Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
2023-03-04 22:38:38 +05:30
module Admin
class BackgroundMigrationsController < ApplicationController
feature_category :database
urgency :low
around_action :support_multiple_databases
def index
@relations_by_tab = {
'queued' => batched_migration_class.queued.queue_order,
2023-06-20 00:43:36 +05:30
'finalizing' => batched_migration_class.finalizing.queue_order,
2023-03-04 22:38:38 +05:30
'failed' => batched_migration_class.with_status(:failed).queue_order,
'finished' => batched_migration_class.with_status(:finished).queue_order.reverse_order
}
@current_tab = @relations_by_tab.key?(params[:tab]) ? params[:tab] : 'queued'
@migrations = @relations_by_tab[@current_tab].page(params[:page])
@successful_rows_counts = batched_migration_class.successful_rows_counts(@migrations.map(&:id))
@databases = Gitlab::Database.db_config_names
end
2022-07-16 23:28:13 +05:30
2023-03-04 22:38:38 +05:30
def show
@migration = batched_migration_class.find(params[:id])
2022-07-16 23:28:13 +05:30
2023-03-04 22:38:38 +05:30
@failed_jobs = @migration.batched_jobs.with_status(:failed).page(params[:page])
end
2021-09-04 01:27:46 +05:30
2023-03-04 22:38:38 +05:30
def pause
migration = batched_migration_class.find(params[:id])
migration.pause!
2021-09-30 23:02:18 +05:30
2023-03-04 22:38:38 +05:30
redirect_back fallback_location: { action: 'index' }
end
2021-09-30 23:02:18 +05:30
2023-03-04 22:38:38 +05:30
def resume
migration = batched_migration_class.find(params[:id])
migration.execute!
2021-09-30 23:02:18 +05:30
2023-03-04 22:38:38 +05:30
redirect_back fallback_location: { action: 'index' }
end
2021-09-30 23:02:18 +05:30
2023-03-04 22:38:38 +05:30
def retry
migration = batched_migration_class.find(params[:id])
migration.retry_failed_jobs! if migration.failed?
2021-11-11 11:23:49 +05:30
2023-03-04 22:38:38 +05:30
redirect_back fallback_location: { action: 'index' }
end
2021-11-11 11:23:49 +05:30
2023-03-04 22:38:38 +05:30
private
2021-09-04 01:27:46 +05:30
2023-03-04 22:38:38 +05:30
def support_multiple_databases
Gitlab::Database::SharedModel.using_connection(base_model.connection) do
yield
end
2022-07-16 23:28:13 +05:30
end
2023-03-04 22:38:38 +05:30
def base_model
@selected_database = params[:database] || Gitlab::Database::MAIN_DATABASE_NAME
2022-07-16 23:28:13 +05:30
2023-03-04 22:38:38 +05:30
Gitlab::Database.database_base_models[@selected_database]
end
2022-07-16 23:28:13 +05:30
2023-03-04 22:38:38 +05:30
def batched_migration_class
@batched_migration_class ||= Gitlab::Database::BackgroundMigration::BatchedMigration
end
2021-09-04 01:27:46 +05:30
end
end