Closed justechn closed 6 years ago
I think I found a solution. The native sequelize dropAllTables works great.
return mockedSequelize
.getQueryInterface()
.dropAllTables({ 'logging': logging })
.then(function () {
logging && console.log('SequelizeMocking - Context is restored');
});
should I submit a PR to get this changed?
Sure, this is a good idea
Maybe try to add some tests to check your needs into the pull request
Many thanks for your work
Cheers
Further to this (and perhaps scarier), I find that the existing version of restore
drops all of the tables in my actual database. The dropAllTables
solution does not have this issue.
Hi,
Have you got a pull-request ?
Shall I only change this line https://github.com/rochejul/sequelize-mocking/blob/master/lib/sequelize-mocking.js#L226 with:
return mockedSequelize
.getQueryInterface()
.dropAllTables({ 'logging': logging })
.then(function () {
logging && console.log('SequelizeMocking - Context is restored');
});
Many thanks for your feedback
Cheers
Yes, that is the change I made. https://github.com/justechn/sequelize-mocking/commit/73f9e9b65312ac1b529235ba971de09a9aa0dc2c
I forked the repo and made the changes, but it caused the tests to fail. I have not had time to dig into why.
Copy that
If I have some times, I will look on it
Many thanks
Cheers
I am getting the following error from this library when the tests are done
ER_ROW_IS_REFERENCED: Cannot delete or update a parent row: a foreign key constraint fails
This is obviously because I have foreign keys in my database, so I looked to see how sequelize handles this internally and I found in the query-interface.js on line 238
So I tried to modify the restore function in your module to do the same
but I still get the same error, so something is not working. Do you have any idea what I am doing wrong?