kitloong / laravel-migrations-generator

Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.
MIT License
2.44k stars 270 forks source link

Inconsistent ordering in squashed migration #167

Closed calebdw closed 1 year ago

calebdw commented 1 year ago

Describe the bug Hello!

I'm using this package to generate a dummy (squashed) migration file for Larastan to read since it doesn't support reading Postgres Schema Dumps.

However, I've noticed that if I regenerate the migration file (even when there have not been any schema changes) that a few lines are reordered which necessitates redundant git commits.

To Reproduce Steps to reproduce the behavior:

  1. Create several tables
  2. Run php artisan migrate:generate --table-filename create_tables.php --skip-log --skip-proc --skip-views --squash
  3. Commit changes
  4. Re-run command in Step. 2.
  5. See changed migration file.

Expected behavior I expect the migration file to remain unchanged when there have not been any schema changes.

Screenshots image

Details (please complete the following information):

Additional context Add any other context about the problem here.

kitloong commented 1 year ago

Hi @CalebDW , thank you for reporting.

The table indexes are randomly ordered.

This is more like a feature request to sort the table indexes to maintain consistent ordering.

I could provide an option to sort the index alphabetically.

Please let me know if this solution would be appropriate for your needs.

calebdw commented 1 year ago

Ah that explains it, and that should work. I just need subsequent calls to create the same migration file when the schema remains unchanged.

I'm not sure that an extra option has to be created for it...what's the harm in making it sort alphabetically by default?

kitloong commented 1 year ago

Initially, I was leaning towards keeping things the same.

But now that I think about it, you might be right. I don't really see any harm in having alphabetical sorting as the default option.

I'll run some tests and if everything works fine I will add this feature.

kitloong commented 1 year ago

@CalebDW Released with tag v6.9.0, thank you.