From fd52df9006871da0696855da7bb79359dd633883 Mon Sep 17 00:00:00 2001
From: Dylan Griffith <dyl.griffith@gmail.com>
Date: Mon, 29 Apr 2024 15:51:23 +1000
Subject: [PATCH] Use MIN_SCHEMA_GITLAB_VERSION in keep for finalizing
 migrations

The OverdueFinalizeBackgroundMigration  keep is a script that is run in
CI for generating merge requests to
[finalize batched background migrations](https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#finalize-a-batched-background-migration).

Per our documentation we can only finalize a batched background
migration added before the last "required stop" which is the minimum
versin someone must upgrade to before they can upgrade to this version
of the code.

We were hardcoding that version in the keep before but now we have
MIN_SCHEMA_GITLAB_VERSION which is exactly for this purpose we don't
need to hardcode it anymore. We also changed from `<` to `<=` now that
this version refers to the version of the last required stop rather than
the first version after it.
---
 keeps/overdue_finalize_background_migration.rb | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/keeps/overdue_finalize_background_migration.rb b/keeps/overdue_finalize_background_migration.rb
index c3870a3d2796d..8c3b1b9243412 100644
--- a/keeps/overdue_finalize_background_migration.rb
+++ b/keeps/overdue_finalize_background_migration.rb
@@ -24,8 +24,6 @@ module Keeps
   #   -k Keeps::OverdueFinalizeBackgroundMigration
   # ```
   class OverdueFinalizeBackgroundMigration < ::Gitlab::Housekeeper::Keep
-    CUTOFF_MILESTONE = '16.8' # Only finalize migrations added before this
-
     def each_change
       each_batched_background_migration do |migration_yaml_file, migration|
         next unless before_cuttoff_milestone?(migration['milestone'])
@@ -218,7 +216,7 @@ def find_queue_method_node(file)
     end
 
     def before_cuttoff_milestone?(milestone)
-      Gem::Version.new(milestone) < Gem::Version.new(CUTOFF_MILESTONE)
+      Gem::Version.new(milestone) <= Gem::Version.new(::Gitlab::Database::MIN_SCHEMA_GITLAB_VERSION)
     end
 
     def each_batched_background_migration
-- 
GitLab