From 184a3600d729ea511a371a507dda71c5ab210cfb Mon Sep 17 00:00:00 2001
From: Pavel Shutsin <pshutsin@gitlab.com>
Date: Tue, 4 Mar 2025 15:21:30 +0100
Subject: [PATCH] Allow migration script to accept base ref

BASE_REF variable can specify base git ref
for migration files. Common example would be
`origin/master` instead of regular `master`
---
 scripts/database/migrate.rb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/database/migrate.rb b/scripts/database/migrate.rb
index a562d3d93234..7bd2aa073f0e 100755
--- a/scripts/database/migrate.rb
+++ b/scripts/database/migrate.rb
@@ -23,6 +23,9 @@
 # 4. Debug mode:
 #    $ ruby scripts/database/migrate.rb --debug
 #    This will run the script with additional debug output for troubleshooting.
+# 5. Custom base branch:
+#    $ BASE_REF=origin/master ruby scripts/database/migrate.rb
+#    This will run the script with origin/master as the base branch for migrations retrieval
 #
 # The script checks for changed migration files in both 'db/migrate' and 'db/post_migrate' directories,
 # and executes the selected migrations for both the main and CI databases.
@@ -32,7 +35,7 @@
 SCRIPT_NAME = File.basename($PROGRAM_NAME)
 MIGRATIONS_DIR = 'db/migrate'
 POST_DEPLOY_MIGRATIONS_DIR = 'db/post_migrate'
-BRANCH_NAME = 'master'
+BRANCH_NAME = ENV.fetch('BASE_REF', 'master')
 
 def require_commands!(*commands)
   missing_commands = commands.reject { |command| system("command", "-v", command, out: File::NULL) }
-- 
GitLab