seed_dump icon indicating copy to clipboard operation
seed_dump copied to clipboard

Topologically sort models to be dumped

Open GarthSnyder opened this issue 8 years ago • 8 comments

This patch sorts models in dependency order before dumping. This makes seed_dump work correctly with foreign keys and dependencies, including indirect relationships through join tables. (Typically, you must include the :id fields to recreate relationships, of course.) See the original blog post by Ryan Stenberg for a detailed explanation of the logic.

There are currently no tests included, but I will add some if you are interested in integrating this patch.

GarthSnyder avatar May 17 '16 23:05 GarthSnyder

My version from a year ago does the same thing. Neither version handles looping dependencies however, where you also need to arrange the records in topological order. I had intended to fix that before offering a PR.

cjheath avatar May 17 '16 23:05 cjheath

Yes, that would be nicer. But there's no guarantee that you can do it in any given case, is there?

GarthSnyder avatar May 17 '16 23:05 GarthSnyder

It the records got populated in the first place with the constraints as they are, then there's always a solution, i.e. barring a mutual mandatory constraint that requires two records be inserted together. Yes, I have actually done this, on occasion - in a product installation process, using a stored proc that suspended one of the FK constraints - a good way to ensure that the records can't be deleted.

cjheath avatar May 17 '16 23:05 cjheath

This is good. Would you still be interested in integrating some tests, @GarthSnyder ?

kofronpi avatar May 09 '17 09:05 kofronpi

Sure, I can do that.

GarthSnyder avatar May 09 '17 18:05 GarthSnyder

That's great, thanks !

kofronpi avatar May 10 '17 08:05 kofronpi

Is there any movement on this? I imagine it's still awaiting tests?

mvastola avatar Oct 03 '17 03:10 mvastola

Any progress? Can we merge this?

3minus1 avatar Jul 09 '18 10:07 3minus1