Knex migration failed with error: The query is empty

Total
5
Shares

I updated knex from 0.21 to 0.95 following their migration guide, Now im geting this Error on CI when its running 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)

but the migration file contains the query’s

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
}

Any help would be greatly appreciated as im getting no where with the error message


Solution

So i was getting this error since Knex 0.95 introduced a new feature https://github.com/knex/knex/pull/4289 so that if an empty array is passed to insert it will throw an error which was not present before

and since we didn’t use that table it was empty and this above migration was trying to insert an empty array which was throwing the error on CI so I just basically handled the Exception with a try-catch block and it got resolved

so as a note look at the change logs carefully

Leave a Reply

Your email address will not be published. Required fields are marked *