Reputation: 13396
Can I use sequelize to create the database schema from the available model? I work on a project that has many migrations missing and no tests. To run tests I need to create a new db (sqlite3) but I cannot initialize its schema using migration (because they are missing). Is it possible to use the models to create the schema?
Upvotes: 4
Views: 4516
Reputation: 2307
Is it possible to use the models to create the schema? ... Because I want to do this in Mocha config so whenever any test runs, I'm sure that it runs on an up to date test db. But because sync is async I have no idea how to do this
Assuming Sequelize CLI was used, Here's a way to ensure you have an updated db in any mocha test:
// Force sync without migrations
// This can be run at the top of every individual test suite
before(function () {
return require('../../models').sequelize.sync({ force: true })
})
The path '../../models'
points to models/index.js
which Sequelize CLI creates for you.
Upvotes: 4
Reputation: 1152
Yes. If you just sync sequelize in your application, the models will create the database tables for you
Upvotes: 4