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 9aaaaf6 commit 8686008
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Migration/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function checkIntegrity(
$md5 = md5_file($file);

if(is_null($migrationCount)
|| $fileNumber <= $migrationCount) {
|| $fileNumber <= $migrationCount) {
$result = $this->dbClient->executeSql(implode("\n", [
"select `" . self::COLUMN_QUERY_HASH . "`",
"from `{$this->tableName}`",
Expand Down Expand Up @@ -201,15 +201,19 @@ public function performMigration(

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

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

try {
$parser = new Parser($allSql);
foreach($parser->statements as $sql) {
foreach(explode(";", $allSql) as $sql) {
$sql = trim($sql);
if(!$sql) {
continue;
}

$this->dbClient->executeSql($sql);
$this->recordMigrationSuccess($fileNumber, $md5);
}
$this->recordMigrationSuccess($fileNumber, $md5);
}
catch(DatabaseException $exception) {
throw $exception;
Expand Down

0 comments on commit 8686008

Please sign in to comment.