Reputation: 4331
I am new to Sequelize
and my current project requires me to use it with migrations. I am familiar with migrations what they do and how.
I am coming from Django
background where each sub app has modals, views, apis, urls and migrations in the same folder. i like the structure and want to keep the same in my nodejs app. i am trying to put a feature at one place. it makes more sense to me.
my structure
|---api
|---user
| |--- api.js
| |--- utils.js
| |--- models.js
| |--- index.js
| |--- migrations
| |--- xxx123-migration.js
| |--- xxx1235-migration.js
|---payment
|--- api.js
|--- utils.js
|--- models.js
|--- index.js
|--- migrations
|--- xxx123-migration.js
|--- xxx1235-migration.js
now my problem is that i dont know how to m make Sequelize-cli
point to my folders and look for migrations to generate and run.
Sequelize-cli
generates their own folders for models, config, seeds etc. which I don't want to follow.
any help is appreciated.
Upvotes: 18
Views: 16706
Reputation: 27
based on issues [\https://github.com/sequelize/cli/issues/28]1 we can add flag in model:generate command
(example) : npx sequelize-cli model:generate --name modelName --models-path .\some\ --attributes name:string
make sure models properly imported in models/index.js file
Upvotes: 0
Reputation: 1583
EDIT:
after your updated structure , it is not possible to use .sequelizerc file to do so, because it doesn't support multiple migration folder.
You need to create .sequelizerc
file at project root to override the default path. see here
If I assume api
is the first folder inside project root from your folder structure , the models are in api/user
and migrations are in api/user/migrations
. The following should work:
const path = require('path');
module.exports = {
'config': path.resolve('CONFIGPATHHERE', 'sequelize.js'),
'models-path': path.resolve('api/user', 'sequelize'),
'migrations-path': path.resolve('api/user', 'migrations')
}
make sure you specify sequelize config path.
Upvotes: 21