Skip to content

Commit 8e319c0

Browse files
authored
[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
1 parent f0ef58d commit 8e319c0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Illuminate/Database/Console/Migrations/TableGuesser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class TableGuesser
1010
];
1111

1212
const CHANGE_PATTERNS = [
13-
'/_(to|from|in)_(\w+)_table$/',
14-
'/_(to|from|in)_(\w+)$/',
13+
'/.+_(to|from|in)_(\w+)_table$/',
14+
'/.+_(to|from|in)_(\w+)$/',
1515
];
1616

1717
/**

tests/Database/TableGuesserTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public function testMigrationIsProperlyParsed()
1717
$this->assertSame('users', $table);
1818
$this->assertFalse($create);
1919

20+
[$table, $create] = TableGuesser::guess('add_is_sent_to_crm_column_to_users_table');
21+
$this->assertSame('users', $table);
22+
$this->assertFalse($create);
23+
2024
[$table, $create] = TableGuesser::guess('change_status_column_in_users_table');
2125
$this->assertSame('users', $table);
2226
$this->assertFalse($create);
@@ -36,6 +40,10 @@ public function testMigrationIsProperlyParsedWithoutTableSuffix()
3640
$this->assertSame('users', $table);
3741
$this->assertFalse($create);
3842

43+
[$table, $create] = TableGuesser::guess('add_is_sent_to_crm_column_column_to_users');
44+
$this->assertSame('users', $table);
45+
$this->assertFalse($create);
46+
3947
[$table, $create] = TableGuesser::guess('change_status_column_in_users');
4048
$this->assertSame('users', $table);
4149
$this->assertFalse($create);

0 commit comments

Comments
 (0)