Skip to content

Commit

Permalink
feature: split multiple statements in migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Oct 11, 2023
1 parent 55154da commit 9aaaaf6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Migration/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Gt\Database\Database;
use Gt\Database\Connection\Settings;
use Gt\Database\DatabaseException;
use PhpMyAdmin\SqlParser\Parser;
use SplFileInfo;
use SplFileObject;

Expand Down Expand Up @@ -200,12 +201,15 @@ public function performMigration(

$this->output("Migration $fileNumber: `$file`.");

$sql = file_get_contents($file);
$allSql = file_get_contents($file);
$md5 = md5_file($file);

try {
$this->dbClient->executeSql($sql);
$this->recordMigrationSuccess($fileNumber, $md5);
$parser = new Parser($allSql);
foreach($parser->statements as $sql) {
$this->dbClient->executeSql($sql);
$this->recordMigrationSuccess($fileNumber, $md5);
}
}
catch(DatabaseException $exception) {
throw $exception;
Expand Down

0 comments on commit 9aaaaf6

Please sign in to comment.