Run update inside knex migration

Solution 1:

export function up(knex, Promise) {
  return knex.select()
    .from('Users')
    .then((users) => {
      const nickNames = users.map((user) => {
        return { userId: user.user_id, nickName: getNickName(row) };
      });
      return knex.transaction((trx) => {
        return knex.schema.table('Orders', (table) => table.string('user_nick_name').transacting(trx))
          .then(() => {
            return Promise.all(
              nickNames.map((row) => {
                return knex('Orders')
                .update({ user_nick_name: row.nickName })
                .where('user_id', row.userId)
                .transacting(trx);
              });
            );
      })
      .then(trx.commit)
      .catch(trx.rollback);
    });
  });
}

export function down(knex) {
  return knex.schema.table('Orders', (table) => table.dropColumn('user_nick_name'));
}