Skip to content

Commit c5994be

Browse files
Изменена логика обработки и вывода ошибок
1 parent 79ce4cf commit c5994be

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/ConsoleSqlMigration.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,21 @@ public function down(int $count = 0): array {
6464
exit;
6565
}
6666

67-
foreach ($migrations['success'] as $successMigration) {
68-
Console::writeLine("Миграция {$successMigration['name']} успешно отменена", Console::FG_GREEN);
69-
}
70-
7167
if (array_key_exists('error', $migrations)) {
7268
foreach ($migrations['error'] as $errorMigration) {
73-
Console::writeLine("Ошибка отмены миграции {$errorMigration['name']}", Console::FG_RED);
69+
Console::writeLine("Ошибка отмены миграции {$errorMigration['name']} : " .
70+
PHP_EOL .
71+
$errorMigration['errorMessage'],
72+
Console::FG_RED);
7473
}
7574

7675
exit;
7776
}
7877

78+
foreach ($migrations['success'] as $successMigration) {
79+
Console::writeLine("Миграция {$successMigration['name']} успешно отменена", Console::FG_GREEN);
80+
}
81+
7982
return $migrations;
8083
}
8184

src/SqlMigration.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DateTime;
88
use mepihindeveloper\components\exceptions\SqlMigrationException;
99
use mepihindeveloper\components\interfaces\{DatabaseInterface, SqlMigrationInterface};
10+
use PDOException;
1011
use RuntimeException;
1112

1213
/**
@@ -186,22 +187,22 @@ protected function execute(array $list, int $count, string $type): array {
186187
throw new RuntimeException('Ошибка поиска/чтения миграции');
187188
}
188189

189-
if (!empty($migrationContent)) {
190-
$this->database->beginTransaction();
191-
$this->database->execute($migrationContent);
192-
$this->database->commit();
193-
}
194-
195190
try {
191+
if (!empty($migrationContent)) {
192+
$this->database->beginTransaction();
193+
$this->database->execute($migrationContent);
194+
$this->database->commit();
195+
}
196+
196197
if ($type === self::UP) {
197198
$this->addHistory($migration['name']);
198199
} else {
199200
$this->removeHistory($migration['name']);
200201
}
201202

202203
$migrationInfo['success'][] = $migration;
203-
} catch (SqlMigrationException $exception) {
204-
$migrationInfo['error'][] = $migration;
204+
} catch (SqlMigrationException | PDOException $exception) {
205+
$migrationInfo['error'][] = array_merge($migration, ['errorMessage' => $exception->getMessage()]);
205206

206207
break;
207208
}

0 commit comments

Comments
 (0)