我正在构建使用MongoDB并部署到Heroku的NodeJS应用程序。
我正在使用east migration library,并且希望在部署过程中运行迁移命令。
我该怎么做呢?
我应该派生构建包,还是有更简单的方法?
发布于 2015-04-27 11:31:19
有一种更简单的方法。
当您的应用程序部署到Heroku时,Heroku将执行npm install --production
来安装所有依赖项。完成后,将执行postinstall
脚本。您可以在package.json
文件中定义postinstall
脚本。在此脚本中,您可以运行迁移。
下面是我在Node on Fire-based项目中使用的代码片段。这将在部署到Heroku时执行grunt build
和grunt release
(否则将执行npm install
)。
{
..
"scripts": {
"postinstall": "./node_modules/grunt-cli/bin/grunt build && ./node_modules/grunt-cli/bin/grunt release"
},
..
}
在您的示例中,使用以下值./node_modules/east/bin/east migrate
创建一个postinstall
。这将在Heroku上执行您的迁移。您应该确保在dependencies
中列出east
,而不是devDependencies
,因为Heroku没有安装devDependencies
。您也不能在postinstall
脚本中使用任何全局依赖项,因为您的依赖项永远不会全局安装在Heroku上(使用默认的构建包)。
https://stackoverflow.com/questions/26889431
复制相似问题