From e3927afe195dc1fe385baf00439de18096bbcd22 Mon Sep 17 00:00:00 2001
From: Joas Schilling <coding@schilljs.com>
Date: Thu, 4 Mar 2021 08:49:42 +0100
Subject: [PATCH] Only mark migrations as installed after execution

The problem is that if a developer creates a structural error in their migration file,
they will already be marked as executed and an not be rerun.

Signed-off-by: Joas Schilling <coding@schilljs.com>
---
 lib/private/DB/MigrationService.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index 44707911092..42c3de3ea1e 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -453,8 +453,6 @@ class MigrationService {
 			$toSchema = $instance->changeSchema($this->output, function () use ($toSchema) {
 				return $toSchema ?: new SchemaWrapper($this->connection);
 			}, ['tablePrefix' => $this->connection->getPrefix()]) ?: $toSchema;
-
-			$this->markAsExecuted($version);
 		}
 
 		if ($toSchema instanceof SchemaWrapper) {
@@ -466,6 +464,10 @@ class MigrationService {
 			$this->connection->migrateToSchema($targetSchema);
 			$toSchema->performDropTableCalls();
 		}
+
+		foreach ($toBeExecuted as $version) {
+			$this->markAsExecuted($version);
+		}
 	}
 
 	/**
-- 
GitLab