Skip to content

Conversation

@shaedrich
Copy link
Contributor

@shaedrich shaedrich commented Oct 18, 2024

This change simplifies the patterns used to guess the table name, streamlining it into one RegExp for all current use cases.

It does not change the return value, thus is not a breaking change.

Class history

  • e96e5ab First RegExp added for create table
  • be79fb8 Second RegExp added for add/change/drop column as a separate if
  • b1a80f0 Moved logic from \Illuminate\Database\Console\Migrations\MigrateMakeCommand to \Illuminate\Database\Console\Migrations\TableGuesser, left the logic as is
  • 4528502 Duplicated the RegExps from 2 to 4 to account for missing explicit _table suffix, introducing a foreach wrapping around each if, resulting in each if being called twice (four calls total, one for each RegExp) ([5.7] Allow migration table name to be guessed without _table suffix #26429)

@johanrosenson
Copy link
Contributor

Is it really a simplification? It looks way harder to make changes to the regex now.

@shaedrich
Copy link
Contributor Author

The current implementation needs two loops and four ifs to extract one sub string and one boolean. That's not ideal.

If it's just about readability, the RegExp can have line breaks:

- const PATTERN = '/^(?<method>create)_(?<table>\w+?)(?:_table)?$|(?J)(?<method>add|drop|change).+_(?:to|from|in)_(?J)(?<table>\w+?)(?:_table)?$/';
+ const PATTERN = <<<'EOD'
/
^(?<method>create)_(?<table>\w+?)(?:_table)?$| # e.g. create_users or create_users_table
(?J)(?<method>add|drop|change).+_(?:to|from|in)_(?J)(?<table>\w+?)(?:_table)?$ # e.g. add_slug_column_to_users_table
/x
EOD;

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@shaedrich
Copy link
Contributor Author

I don't expect any less of you

(considering, the bar already being at its lowest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants