From fc2cda12b5af11037dcb5b54df14336d796c385b Mon Sep 17 00:00:00 2001
From: Robin Appelman <robin@icewind.nl>
Date: Wed, 2 Apr 2025 14:29:08 +0200
Subject: [PATCH] fix: use proper migration sorting when checking if a
 migration needs to be executed

Signed-off-by: Robin Appelman <robin@icewind.nl>
---
 lib/private/DB/MigrationService.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index 0b59509eaab..2f4c8131d9f 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -199,9 +199,9 @@ class MigrationService {
 			if ($versionA !== $versionB) {
 				return ($versionA < $versionB) ? -1 : 1;
 			}
-			return ($matchA[2] < $matchB[2]) ? -1 : 1;
+			return strnatcmp($matchA[2], $matchB[2]);
 		}
-		return (basename($a) < basename($b)) ? -1 : 1;
+		return strnatcmp(basename($a), basename($b));
 	}
 
 	/**
@@ -250,7 +250,7 @@ class MigrationService {
 
 		$toBeExecuted = [];
 		foreach ($availableMigrations as $v) {
-			if ($to !== 'latest' && $v > $to) {
+			if ($to !== 'latest' && ($this->sortMigrations($v, $to) > 0)) {
 				continue;
 			}
 			if ($this->shallBeExecuted($v, $knownMigrations)) {