2021-05-19 05:10:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::BackgroundMigrationsController < Admin::ApplicationController
|
|
|
|
feature_category :database
|
2022-04-26 20:08:37 -04:00
|
|
|
urgency :low
|
2021-05-19 05:10:19 -04:00
|
|
|
|
2022-04-29 05:09:48 -04:00
|
|
|
around_action :support_multiple_databases
|
|
|
|
|
2021-05-19 05:10:19 -04:00
|
|
|
def index
|
|
|
|
@relations_by_tab = {
|
|
|
|
'queued' => batched_migration_class.queued.queue_order,
|
2022-04-02 02:09:49 -04:00
|
|
|
'failed' => batched_migration_class.with_status(:failed).queue_order,
|
|
|
|
'finished' => batched_migration_class.with_status(:finished).queue_order.reverse_order
|
2021-05-19 05:10:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@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))
|
2022-04-29 05:09:48 -04:00
|
|
|
@databases = Gitlab::Database.db_config_names
|
2021-05-19 05:10:19 -04:00
|
|
|
end
|
|
|
|
|
2022-04-25 20:08:40 -04:00
|
|
|
def show
|
|
|
|
@migration = batched_migration_class.find(params[:id])
|
2022-05-09 02:08:14 -04:00
|
|
|
|
|
|
|
@failed_jobs = @migration.batched_jobs.with_status(:failed).page(params[:page])
|
2022-04-25 20:08:40 -04:00
|
|
|
end
|
|
|
|
|
2021-07-08 08:08:30 -04:00
|
|
|
def pause
|
|
|
|
migration = batched_migration_class.find(params[:id])
|
2022-04-02 02:09:49 -04:00
|
|
|
migration.pause!
|
2021-07-08 08:08:30 -04:00
|
|
|
|
|
|
|
redirect_back fallback_location: { action: 'index' }
|
|
|
|
end
|
|
|
|
|
|
|
|
def resume
|
|
|
|
migration = batched_migration_class.find(params[:id])
|
2022-04-02 02:09:49 -04:00
|
|
|
migration.execute!
|
2021-07-08 08:08:30 -04:00
|
|
|
|
|
|
|
redirect_back fallback_location: { action: 'index' }
|
|
|
|
end
|
|
|
|
|
2021-08-23 05:10:23 -04:00
|
|
|
def retry
|
|
|
|
migration = batched_migration_class.find(params[:id])
|
|
|
|
migration.retry_failed_jobs! if migration.failed?
|
|
|
|
|
|
|
|
redirect_back fallback_location: { action: 'index' }
|
|
|
|
end
|
|
|
|
|
2021-05-19 05:10:19 -04:00
|
|
|
private
|
|
|
|
|
2022-04-29 05:09:48 -04:00
|
|
|
def support_multiple_databases
|
|
|
|
Gitlab::Database::SharedModel.using_connection(base_model.connection) do
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def base_model
|
2022-05-05 14:08:40 -04:00
|
|
|
@selected_database = params[:database] || Gitlab::Database::MAIN_DATABASE_NAME
|
2022-04-29 05:09:48 -04:00
|
|
|
|
2022-05-05 14:08:40 -04:00
|
|
|
Gitlab::Database.database_base_models[@selected_database]
|
2022-04-29 05:09:48 -04:00
|
|
|
end
|
|
|
|
|
2021-05-19 05:10:19 -04:00
|
|
|
def batched_migration_class
|
2021-08-23 05:10:23 -04:00
|
|
|
@batched_migration_class ||= Gitlab::Database::BackgroundMigration::BatchedMigration
|
2021-05-19 05:10:19 -04:00
|
|
|
end
|
|
|
|
end
|