Reputation: 803
I am working on third-party NODE module which deal with sending emails and storing them in DB, so let's call it mail-module. In order for someone to use its functionalities, it should be enough to import it in his project and use its functions for sending and storing emails.
What makes problem here is that someone who imports mail-module, he needs manually to create DB tables for storing emails because Sequelize CLI does not see migration scripts in separate modules. In mail-module there are Sequelize migration scripts but it's cumbersome for developers to look for it in module, than copy it in his own project and run as it's part of his project.
Is there any way to avoid this manual work and make configuration such that when developer (user of mail-module) run his own migrations scripts, mail-module migration scripts are performed too?
Upvotes: 3
Views: 1774
Reputation: 1845
You don't necessarily need to copy you mail module migrations to the main module. You can specify the --migrations-path
option for db:migrate
command.
Provided, that ./node_modules/.bin/sequelize db:migrate
runs migrations in the main module and you have your mail module migrations directory in, let's say, node_modules/main-module/lib/migrations
, you can combine the commands in the following script in package.json
:
{
...
"scripts": {
"dbs-migrate": "./node_modules/.bin/sequelize db:migrate && ./node_modules/.bin/sequelize db:migrate --migrations-path ./node_modules/mail-module/lib/migrations"
}
}
This way you will run all migrations with the following command: npm run dbs-migrate
. Hope, this solves your problem.
Upvotes: 5