From 17a35afc44a4cd2e676d32a22004817d3bd3fa31 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 2 Aug 2022 15:16:34 +0200 Subject: [PATCH] new migrations, run migrations before upgrade gitlab --- scripts/upgrade | 95 +++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 32bd2ee..73e86da 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -260,6 +260,55 @@ then # While the current version is not the last version, do an upgrade while [ "$last_version" != "$current_version" ] do + # https://docs.gitlab.com/ee/update/#checking-for-background-migrations-before-upgrading + if dpkg --compare-versions "$current_version" "ge" "12.9"; then + checkBackgroundMigration=1 + else + checkBackgroundMigration=0; + fi + if dpkg --compare-versions "$current_version" "ge" "15.1"; then + checkDBBackgroundMigration=2 + elif dpkg --compare-versions "$current_version" "ge" "14.0"; then + checkDBBackgroundMigration=1 + else + checkDBBackgroundMigration=0; + fi + if dpkg --compare-versions "$current_version" "ge" "14.7"; then + checkBatchedBackgroundMigration=1 + else + checkBatchedBackgroundMigration=0; + fi + + counter=0 + while [ $checkBackgroundMigration -eq 1 ] || [ $checkDBBackgroundMigration -ge 1 ] || [ $checkBatchedBackgroundMigration -eq 1 ] + do + counter=$((counter + 1)) + if [ $counter -gt 1200 ] + then + ynh_print_warn --message="Timeout: a background migration runs for at least 20min !" + break + fi + + if [ $checkBackgroundMigration -eq 1 ] && gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.remaining' | grep -q -w 0 + then + checkBackgroundMigration=0 + fi + + if [ $checkDBBackgroundMigration -eq 2 ] && gitlab-rails runner -e production 'puts Gitlab::Database::BackgroundMigration::BatchedMigration.queued.count' | grep -q -w 0 + then + checkDBBackgroundMigration=0 + elif [ $checkDBBackgroundMigration -eq 1 ] && gitlab-rails runner -e production 'puts Gitlab::Database::BackgroundMigrationJob.pending' | wc -l | grep -q -w 0 + then + checkDBBackgroundMigration=0 + fi + + if [ $checkBatchedBackgroundMigration -eq 1 ] && echo "select COUNT(*) from batched_background_migrations where status <> 3;" | gitlab-psql -t -A | grep -q -w 0 + then + checkBatchedBackgroundMigration=0 + fi + ynh_print_info --message="Wait for the migration in the background to finish" + sleep 1 + done current_major_version=${current_version%%.*} @@ -313,52 +362,6 @@ then ynh_secure_remove --file="/tmp/gitlab_upgrade_$current_version.log" fi fi - - - # https://docs.gitlab.com/ee/update/#checking-for-background-migrations-before-upgrading - if dpkg --compare-versions "$current_version" "ge" "12.9"; then - checkBackgroundMigration=1 - else - checkBackgroundMigration=0; - fi - if dpkg --compare-versions "$current_version" "ge" "14.0"; then - checkDBBackgroundMigration=1 - else - checkDBBackgroundMigration=0; - fi - if dpkg --compare-versions "$current_version" "ge" "14.7"; then - checkBatchedBackgroundMigration=1 - else - checkBatchedBackgroundMigration=0; - fi - - counter=0 - while [ $checkBackgroundMigration -eq 1 ] || [ $checkDBBackgroundMigration -eq 1 ] || [ $checkBatchedBackgroundMigration -eq 1 ] - do - counter=$((counter + 1)) - if [ $counter -gt 1200 ] - then - ynh_print_warn --message="Timeout: a background migration runs for at least 20min !" - break - fi - - if [ $checkBackgroundMigration -eq 1 ] && gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.remaining' | grep -q -w 0 - then - checkBackgroundMigration=0 - fi - - if [ $checkDBBackgroundMigration -eq 1 ] && gitlab-rails runner -e production 'puts Gitlab::Database::BackgroundMigrationJob.pending' | wc -l | grep -q -w 0 - then - checkDBBackgroundMigration=0 - fi - - if [ $checkBatchedBackgroundMigration -eq 1 ] && echo "select COUNT(*) from batched_background_migrations where status <> 3;" | gitlab-psql -t -A | grep -q -w 0 - then - checkBatchedBackgroundMigration=0 - fi - ynh_print_info --message="Wait for the migration in the background to finish" - sleep 1 - done done fi