Migrations in Sequelize in my own folder structure(Sequelize 中的迁移在我自己的文件夹结构中)
问题描述
我是 Sequelize
的新手,我当前的项目要求我将它与迁移一起使用.我熟悉迁移他们的工作和方式.我来自 Django
背景,其中每个子应用程序在同一个文件夹中都有模式、视图、api、url 和迁移.我喜欢这种结构,并希望在我的 nodejs 应用程序中保持相同.我正在尝试将一项功能放在一个地方.这对我来说更有意义.
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.
我的结构
|---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
现在我的问题是我不知道如何让 Sequelize-cli
指向我的文件夹并查找要生成和运行的迁移.
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
为我不想关注的模型、配置、种子等生成自己的文件夹.
Sequelize-cli
generates their own folders for models, config, seeds etc. which I don't want to follow.
感谢任何帮助.
推荐答案
在您更新结构后,无法使用 .sequelizerc 文件来执行此操作,因为它不支持多个迁移文件夹.
after your updated structure , it is not possible to use .sequelizerc file to do so, because it doesn't support multiple migration folder.
您需要在项目根目录创建 .sequelizerc
文件以覆盖默认路径.参见这里
You need to create .sequelizerc
file at project root to override the default path. see here
如果我假设 api
是文件夹结构中项目根目录中的第一个文件夹,则模型位于 api/user
中,迁移位于 api/user/迁移
.以下应该有效:
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')
}
确保您指定了 sequelize 配置路径.
make sure you specify sequelize config path.
这篇关于Sequelize 中的迁移在我自己的文件夹结构中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Sequelize 中的迁移在我自己的文件夹结构中


基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01