Skip to content

Commit

Permalink
[10.x] Guess table name correctly in migrations if column's name have…
Browse files Browse the repository at this point in the history
… ('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
  • Loading branch information
i350 committed Sep 18, 2023
1 parent f0ef58d commit 8e319c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Console/Migrations/TableGuesser.php
Expand Up @@ -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+)$/',
];

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Database/TableGuesserTest.php
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 8e319c0

Please sign in to comment.