From da20e47ec478fafd78e42b6f4c60f45a82c23aaf Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Wed, 7 Aug 2024 10:47:26 +0900 Subject: [PATCH] fix: migration broke in laravel v11.15 (#224) --- CHANGELOG.md | 6 ++++++ composer.json | 2 +- src/Eloquent/Model.php | 6 +++--- src/Schema/Grammar.php | 28 ++++++++++++++++++++-------- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c12fc6..2fe6b06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v8.2.0 (2024-08-05) + +> [!NOTE] Minimum supported Laravel version is bumped to 11.15.0 for #224. + +- Fixed an issue where Schema changes were applied twice. (#224) + # v8.1.3 (2024-06-24) Fixed diff --git a/composer.json b/composer.json index c9d3327..86dbed7 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "php": "^8.2", "ext-grpc": "*", "ext-json": "*", - "laravel/framework": "^11", + "laravel/framework": "^11.15.0", "google/cloud-spanner": "^1.58.4", "grpc/grpc": "^1.42", "symfony/cache": "~7", diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index 797be74..9d36deb 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -24,7 +24,7 @@ use Illuminate\Support\Str; /** - * @mixin Builder + * @mixin Builder */ class Model extends BaseModel { @@ -42,7 +42,7 @@ class Model extends BaseModel public $incrementing = false; /** - * @param BaseModel|Relation $query + * @param BaseModel|Relation $query * @param mixed $value * @param string|null $field * @return BuilderContract @@ -59,7 +59,7 @@ public function resolveRouteBindingQuery($query, $value, $field = null) * @param string $childType * @param mixed $value * @param string|null $field - * @return Relation + * @return Relation */ protected function resolveChildRouteBindingQuery($childType, $value, $field) { diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index 6164901..3a40799 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -115,14 +115,19 @@ public function compileCreate(Blueprint $blueprint, Fluent $command) * * @param Blueprint $blueprint * @param Fluent $command - * @return string[] + * @return list|string */ public function compileAdd(Blueprint $blueprint, Fluent $command) { - return $this->prefixArray( - 'alter table '.$this->wrapTable($blueprint).' add column', - $this->getColumns($blueprint) + $column = $command->column; + + $sql = sprintf('alter table %s add column %s %s', + $this->wrapTable($blueprint), + $this->wrap($column), + $this->getType($column), ); + + return $this->addModifiers($sql, $blueprint, $column); } /** @@ -131,14 +136,19 @@ public function compileAdd(Blueprint $blueprint, Fluent $command) * @param Blueprint $blueprint * @param Fluent $command * @param Connection $connection - * @return string[] + * @return list|string */ public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection) { - return $this->prefixArray( - 'alter table '.$this->wrapTable($blueprint).' alter column', - $this->getChangedColumns($blueprint) + $column = $command->column; + + $sql = sprintf('alter table %s alter column %s %s', + $this->wrapTable($blueprint), + $this->wrap($column), + $this->getType($column), ); + + return $this->addModifiers($sql, $blueprint, $column); } /** @@ -830,6 +840,8 @@ protected function formatTimestampValue(Fluent $column, mixed $value): string /** * Compile the blueprint's column definitions. * + * @deprecated Not used anymore. Will be deleted in 9.x. + * * @param Blueprint $blueprint * @return array */