From 8e319c04f02c84949e07dedd56541735655575ab Mon Sep 17 00:00:00 2001 From: Islam Abdelfattah Date: Mon, 18 Sep 2023 18:16:33 +0300 Subject: [PATCH] [10.x] Guess table name correctly in migrations if column's name have ('to', 'from' and/or 'in') terms (#48437) * Match table name that not includes ('to', 'from' and 'in') * Add test cases that cover the case of having "to" in column name during migration creation * Simplify the regex --- .../Database/Console/Migrations/TableGuesser.php | 4 ++-- tests/Database/TableGuesserTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Console/Migrations/TableGuesser.php b/src/Illuminate/Database/Console/Migrations/TableGuesser.php index 82dfbddbbceb..30bd53096e06 100644 --- a/src/Illuminate/Database/Console/Migrations/TableGuesser.php +++ b/src/Illuminate/Database/Console/Migrations/TableGuesser.php @@ -10,8 +10,8 @@ class TableGuesser ]; const CHANGE_PATTERNS = [ - '/_(to|from|in)_(\w+)_table$/', - '/_(to|from|in)_(\w+)$/', + '/.+_(to|from|in)_(\w+)_table$/', + '/.+_(to|from|in)_(\w+)$/', ]; /** diff --git a/tests/Database/TableGuesserTest.php b/tests/Database/TableGuesserTest.php index 174463ea8685..f983995e4dd5 100644 --- a/tests/Database/TableGuesserTest.php +++ b/tests/Database/TableGuesserTest.php @@ -17,6 +17,10 @@ public function testMigrationIsProperlyParsed() $this->assertSame('users', $table); $this->assertFalse($create); + [$table, $create] = TableGuesser::guess('add_is_sent_to_crm_column_to_users_table'); + $this->assertSame('users', $table); + $this->assertFalse($create); + [$table, $create] = TableGuesser::guess('change_status_column_in_users_table'); $this->assertSame('users', $table); $this->assertFalse($create); @@ -36,6 +40,10 @@ public function testMigrationIsProperlyParsedWithoutTableSuffix() $this->assertSame('users', $table); $this->assertFalse($create); + [$table, $create] = TableGuesser::guess('add_is_sent_to_crm_column_column_to_users'); + $this->assertSame('users', $table); + $this->assertFalse($create); + [$table, $create] = TableGuesser::guess('change_status_column_in_users'); $this->assertSame('users', $table); $this->assertFalse($create);