Knex 迁移失败并出现错误:查询为空

moh*_*had 6 javascript postgresql node.js knex.js

我按照他们的迁移指南将 knex 从 0.21 更新到 0.95,现在我在 CI 运行时收到此错误npx knex migrate:latest

migration file "20191104160706_migrate-appsflyer_customers.js" failed
migration failed with error: The query is empty
    at createQueryBuilder (/home/circleci/backend/node_modules/knex/lib/knex-builder/make-knex.js:313:26)

Run Code Online (Sandbox Code Playgroud)

但迁移文件包含查询的

async function up (knex) {
  // language=Postgres
  const { rows } = await knex.raw(`
    SELECT * FROM appsflyer_customer;
  `)
  const mappedRows = rows.map(row => ({
    user_id: row.user_id,
    advertising_id_type: 'appsflyer',
    advertising_id: row.appsflyer_device_id
  }))
  await knex('device_advertising_association')
    .insert(mappedRows)
}
async function down (knex) {
  await knex.raw(`
    DELETE FROM device_advertising_association WHERE user_id NOTNULL;
  `)
}
module.exports = {
  up, down
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,因为我没有收到错误消息

moh*_*had 13

所以我收到这个错误,因为 Knex 0.95 引入了一个新功能https://github.com/knex/knex/pull/4289,这样如果传递一个空数组来插入,它将抛出一个以前不存在的错误

因为我们没有使用该表,所以它是空的,并且上面的迁移试图插入一个空数组,这会在 CI 上引发错误,所以我基本上只是用 try-catch 块处理了异常,它就得到了解决

所以请注意仔细查看更改日志