node-sql-fixtures icon indicating copy to clipboard operation
node-sql-fixtures copied to clipboard

Delete fixtures

Open akohout opened this issue 9 years ago • 5 comments

In my integration test suite I insert fixtures in the beforeEach hook, and I clear them in the afterEach hook. For clearing, I use what you suggest in the readme - use knex and manually clear all the databases. I think that this is a usual use case for your library and should be provided in the future :)

akohout avatar Nov 26 '14 14:11 akohout

Hey Alexander,

Thanks for letting me know about MySQL, I updated the README.

I agree it'd be nice if sql-fixtures could clear out data, but not sure how I'd go about it. Any ideas? Reversing the fixture spec and deleting it backwards is one idea, but that might be asking for trouble. Or just having sql-fixtures truncate all the tables is another idea.

city41 avatar Nov 26 '14 15:11 city41

I haven't looked through the code in detail yet, so I can't tell you how to do that. We can just leave it open for the moment and just see if anyone can contribute. Maybe I can find some time to fix it if I have to deal with your library more often :)

akohout avatar Nov 26 '14 15:11 akohout

I was more wondering about general approaches. It will be hard for sql-fixtures to know if it can successfully delete something without violating foreign key constraints, and not sure I want to dig into disabling them.

Anyway, I'll ponder it. I think the library in general could use a refactoring and clean up, I hope to get to that this weekend. From there, it should be easier to add new features.

city41 avatar Nov 26 '14 15:11 city41

+1

rfink avatar Apr 06 '15 18:04 rfink

Or just having sql-fixtures truncate all the tables is another idea.

I think it is a good enough approach. pow-mongodb-fixtures handels it like this: https://github.com/powmedia/pow-mongodb-fixtures#clearallandloaddata-callback, and I found it more than enough.

https://github.com/steven-ferguson/knex-cleaner could be helpful for this.

BenjaminHorn avatar Feb 19 '16 16:02 BenjaminHorn