From 8686008d5808a3a56b1e6d8a04737fbf650f4161 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Wed, 11 Oct 2023 15:26:50 +0100 Subject: [PATCH] feature: split multiple statements in migrations --- src/Migration/Migrator.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Migration/Migrator.php b/src/Migration/Migrator.php index 4d36b8c..63dd4c2 100644 --- a/src/Migration/Migrator.php +++ b/src/Migration/Migrator.php @@ -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}`", @@ -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;