From 5111f8bd455c9e788cc5ad2fa87df8193c595c53 Mon Sep 17 00:00:00 2001 From: Amir Hossein Shokri Date: Sun, 10 Aug 2025 22:20:39 +0330 Subject: [PATCH 1/3] improve migration table name guesser --- .../Database/Console/Migrations/TableGuesser.php | 11 +++++++++++ tests/Database/TableGuesserTest.php | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Illuminate/Database/Console/Migrations/TableGuesser.php b/src/Illuminate/Database/Console/Migrations/TableGuesser.php index 30bd53096e06..2c90387b06fc 100644 --- a/src/Illuminate/Database/Console/Migrations/TableGuesser.php +++ b/src/Illuminate/Database/Console/Migrations/TableGuesser.php @@ -14,6 +14,11 @@ class TableGuesser '/.+_(to|from|in)_(\w+)$/', ]; + const DROP_PATTERNS = [ + '/^drop_(\w+)_table$/', + '/^drop_(\w+)$/', + ]; + /** * Attempt to guess the table name and "creation" status of the given migration. * @@ -33,5 +38,11 @@ public static function guess($migration) return [$matches[2], $create = false]; } } + + foreach (self::DROP_PATTERNS as $pattern) { + if (preg_match($pattern, $migration, $matches)) { + return [$matches[1], $create = false]; + } + } } } diff --git a/tests/Database/TableGuesserTest.php b/tests/Database/TableGuesserTest.php index f983995e4dd5..d0a04c07d16f 100644 --- a/tests/Database/TableGuesserTest.php +++ b/tests/Database/TableGuesserTest.php @@ -28,6 +28,10 @@ public function testMigrationIsProperlyParsed() [$table, $create] = TableGuesser::guess('drop_status_column_from_users_table'); $this->assertSame('users', $table); $this->assertFalse($create); + + [$table, $create] = TableGuesser::guess('drop_users_table'); + $this->assertSame('users', $table); + $this->assertFalse($create); } public function testMigrationIsProperlyParsedWithoutTableSuffix() @@ -51,5 +55,9 @@ public function testMigrationIsProperlyParsedWithoutTableSuffix() [$table, $create] = TableGuesser::guess('drop_status_column_from_users'); $this->assertSame('users', $table); $this->assertFalse($create); + + [$table, $create] = TableGuesser::guess('drop_users'); + $this->assertSame('users', $table); + $this->assertFalse($create); } } From 446fbb20e3b9eeb92a6348d72c9a1308b4e13a0e Mon Sep 17 00:00:00 2001 From: Amir Hossein Shokri Date: Sun, 10 Aug 2025 22:40:32 +0330 Subject: [PATCH 2/3] change guesser method comment --- .../Database/Console/Migrations/MigrateMakeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php index ac5077f58d79..65200d12aba9 100644 --- a/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php @@ -86,7 +86,7 @@ public function handle() } // Next, we will attempt to guess the table name if this the migration has - // "create" in the name. This will allow us to provide a convenient way + // "create" or "drop" in the name. This will allow us to provide a convenient way // of creating migrations that create new tables for the application. if (! $table) { [$table, $create] = TableGuesser::guess($name); From f3e10881b437fe9ca030d7859147506c9c93de8f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 10 Aug 2025 18:51:24 -0500 Subject: [PATCH 3/3] Update MigrateMakeCommand.php --- .../Database/Console/Migrations/MigrateMakeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php index 65200d12aba9..ac5077f58d79 100644 --- a/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php @@ -86,7 +86,7 @@ public function handle() } // Next, we will attempt to guess the table name if this the migration has - // "create" or "drop" in the name. This will allow us to provide a convenient way + // "create" in the name. This will allow us to provide a convenient way // of creating migrations that create new tables for the application. if (! $table) { [$table, $create] = TableGuesser::guess($name);