laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

[Proposal] Less verbose make:migration input #1165

Open lorisleiva opened 6 years ago

lorisleiva commented 6 years ago

Hi 👋,

Currently, when generating a migration that creates a new table I write :

php artisan make:migration create_subscriptions_table --create=subscriptions
  1. Since it always follows the same convention, i.e. create_$tableName_table, I thought it could be a good idea to provide this convention as a default migration name when the name argument is omitted and the create option is provided.
  2. We could also decide on a good default convention for table updates when only the table option is provided.
  3. Whilst updating this command, we could also give the options create and table, the respective shortcuts -c and -t.

Note: it goes without saying that if the user provides a name argument, the command behaves the same as it currently does. So no breaking changes here.

The bash command above could then be shorten to:

php artisan make:migration --create=subscriptions
php artisan make:migration -c subscriptions
# Both generate a migration named: create_subscriptions_table

If you guys, girls and agender people think it's a good idea, I am more than happy to open a PR.

💪💾

sisve commented 6 years ago

Two of the suggestions are reasonable default values for the migration name in case it isn't provided, and one is to mangle the parameter names into something unreadable.

I'm +2/3 to this suggestion as it is currently written. Do we really have to add short parameter names?

lorisleiva commented 6 years ago

Thanks for the input. Glad to see you're on board with the main part of this proposal.

I don't really see any inconvenience in adding two non conflictual shortcuts in options that are frequently used. Could you please provide some of your cons regarding that matter?

fletch3555 commented 6 years ago

Agreed. I don't see a downside to shorthand parameter names, SO LONG AS the long-form continue to exist as well. Laravel is full of short-hand features for those that prefer it, but nobody is forced to use them.

joshuadegier commented 6 years ago

What a coincidence, I wans't aware of this laravel/ideas repository and created a first draft for this a few minutes ago. While creating a few migration for a new project I noticed in most cases where I create a new table, I was using the same format: create_$tablename_table.

  1. The modified file can be found in this fork: https://github.com/PendoNL/framework/blob/5.6/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php (commit diff here: https://github.com/PendoNL/framework/commit/619779395d419b788b46789579587edf6ef2baf5).

  2. I'm not sure if there's a good default for updating a table. When I look at my personal situation it's very diverse of what names I want to give them, like add_active_field_to_posts, add_address_fields_to_post, remove_unused_fields_from_posts, etc. So,.. not sure about that one or what default fits best for all cases. Having an update_posts_table migration is just to vague for my taste.

  3. Fair enough! That's a few key strokes less ;-)

lorisleiva commented 6 years ago

@joshuadegier Nice, thanks for sharing. I totally agree with your opinion on the updating convention. The issue is that if we provide a default name for --create, then name will be an optional parameter. Thus, we have to also provide some default for --table. And like you said update_$tablename_table is just too vague and basically not something that people use.

joshuadegier commented 6 years ago

In my code there's only an exception thrown if the parameter is missing when using any other than --create. Seems a fair solution, I'll just leave it here to gather some more thoughts of others.