【发布时间】:2020-03-28 04:53:21
【问题描述】:
我已经从 Heroku 安装了 PostgreSQL 插件,但是我在后端使用了 Knex.js,就像我之前使用 SQLite 一样,我遇到了以下错误。
我正在为网站和移动应用程序构建后端并尝试将其部署到 Heroku,在开发时我使用 SQLite,但我发现由于我使用的是 Knex.js,因此我可以轻松地转移到 Postgres 附加组件来自 Heroku。在postbuild 上运行knex migrate:latest 时,我遇到了这个问题。
no such file or directory, scandir '/tmp/build_46fb7aa66e7e3cea06d2f04a21ad9249/migrations'
这是我的 knex 文件:
// Update with your config settings.
module.exports = {
development: {
client: 'sqlite3',
connection: {
filename: './src/database/db.sqlite'
},
migrations: {
directory: './src/database/migrations'
},
useNullAsDefault: true
},
test: {
client: 'sqlite3',
connection: {
filename: './src/database/test.sqlite'
},
migrations: {
directory: './src/database/migrations'
},
useNullAsDefault: true
},
staging: {
client: 'postgresql',
connection: {
database: 'my_db',
user: 'username',
password: 'password'
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
},
production: {
client: 'pg',
debug: true,
connection: process.env.DATABASE_URL,
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
},
ssl: true
}
};
和我的关系
const knex = require('knex')
const configuration = require('../../knexfile')
const config = process.env.NODE_ENV
const connection = knex(configuration[config])
module.exports = connection
测试和开发的迁移工作正常
我也不知道这之后是否会起作用,所以如果有人有任何经验,我可以使用任何帮助
【问题讨论】:
-
"但我认为由于我使用的是 knex,因此我可以轻松地从 heroku 转移到 Postgre 插件"——这是个坏主意。 始终使用您在生产中定位的同一数据库进行开发。即使有像 knex 这样的库,数据库引擎也不能互相替代。
-
为什么不在生产配置中提供迁移目录?
-
哦,可能是,我去查一下
-
成功了!谢谢
标签: node.js postgresql heroku knex.js