cviebrock / sequel-pro-laravel-export

A Sequel Pro / Sequel Ace bundle to generate Laravel migration files from existing tables.
MIT License
921 stars 55 forks source link

(Enhancement) Foreign keys should be exported so they're run after referenced tables are exported when multiple tables are being exported #29

Closed pbrisson closed 3 years ago

pbrisson commented 4 years ago

When dealing with a large amount of tables, the migrations are created in alphabetical order.

Foreign keys are properly exported in the migrations; however, the fact referenced table exists or not isn't taken in consideration.

If a table named "aaa" references a table named "zzz" on delete cascade, for example, it will fail when you run migrations, since the table "zzz" won't be existing at this point.

I'm wondering if it would be possible to export all foreign keys as a separate migration, after all tables have been processed, when the bundle detects multiple tables are being exported?

I'm using bundle version 1.5.0 with Sequel Pro 1.1.2 version 4541 (602e11a) on MariaDB 10.3.17-MariaDB-0+deb10u1 (Debian 10).

cviebrock commented 4 years ago

Good idea. I'll try tackling this shortly, but happy to accept a PR if you want to contribute a fix!

rootrus commented 3 years ago

Good idea. I'll try tackling this shortly, but happy to accept a PR if you want to contribute a fix!

I have added this function in and created a PR

https://github.com/cviebrock/sequel-pro-laravel-export/pull/37

cviebrock commented 3 years ago

Thanks @rootrus! I did a bit of clean-up and this is now supported in the 2.0.1 release.