Skip to content

Commit ab9e249

Browse files
[12.x] Add drop patterns support to TableGuesser for drop migrations (#56608)
* improve migration table name guesser * change guesser method comment * Update MigrateMakeCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent ac498ff commit ab9e249

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class TableGuesser
1414
'/.+_(to|from|in)_(\w+)$/',
1515
];
1616

17+
const DROP_PATTERNS = [
18+
'/^drop_(\w+)_table$/',
19+
'/^drop_(\w+)$/',
20+
];
21+
1722
/**
1823
* Attempt to guess the table name and "creation" status of the given migration.
1924
*
@@ -33,5 +38,11 @@ public static function guess($migration)
3338
return [$matches[2], $create = false];
3439
}
3540
}
41+
42+
foreach (self::DROP_PATTERNS as $pattern) {
43+
if (preg_match($pattern, $migration, $matches)) {
44+
return [$matches[1], $create = false];
45+
}
46+
}
3647
}
3748
}

tests/Database/TableGuesserTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function testMigrationIsProperlyParsed()
2828
[$table, $create] = TableGuesser::guess('drop_status_column_from_users_table');
2929
$this->assertSame('users', $table);
3030
$this->assertFalse($create);
31+
32+
[$table, $create] = TableGuesser::guess('drop_users_table');
33+
$this->assertSame('users', $table);
34+
$this->assertFalse($create);
3135
}
3236

3337
public function testMigrationIsProperlyParsedWithoutTableSuffix()
@@ -51,5 +55,9 @@ public function testMigrationIsProperlyParsedWithoutTableSuffix()
5155
[$table, $create] = TableGuesser::guess('drop_status_column_from_users');
5256
$this->assertSame('users', $table);
5357
$this->assertFalse($create);
58+
59+
[$table, $create] = TableGuesser::guess('drop_users');
60+
$this->assertSame('users', $table);
61+
$this->assertFalse($create);
5462
}
5563
}

0 commit comments

Comments
 (0)