city41 / node-sql-fixtures

SQL fixtures for Node.js in PostgreSQL, MySQL, MariaDB and SQLite
http://city41.github.io/node-sql-fixtures/
MIT License
81 stars 17 forks source link

Delete fixtures #18

Open akohout opened 9 years ago

akohout commented 9 years ago

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 :)

city41 commented 9 years ago

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.

akohout commented 9 years ago

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 :)

city41 commented 9 years ago

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.

rfink commented 9 years ago

+1

BenjaminHorn commented 8 years ago

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.