Add check for duplicate migrations names when loading migrations

[MAILPOET-5416]
This commit is contained in:
Rostislav Wolny
2023-07-24 15:26:52 +02:00
committed by Aschepikov
parent ec8b5260dd
commit 725d81077f
5 changed files with 46 additions and 1 deletions

View File

@ -55,10 +55,15 @@ class Repository {
* @return array<array{level: string, name: string}>
*/
public function loadAll(): array {
return array_merge(
$migrations = array_merge(
$this->loadForLevel(self::MIGRATIONS_LEVEL_DB),
$this->loadForLevel(self::MIGRATIONS_LEVEL_APP)
);
$duplicateNames = array_diff_assoc(array_column($migrations, 'name'), array_unique(array_column($migrations, 'name')));
if (!empty($duplicateNames)) {
throw MigratorException::duplicateMigrationNames($duplicateNames);
}
return $migrations;
}
private function loadForLevel(string $level): array {