Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
Using console log in Knex migration not logging

My issue: The console.log('tableNobject: ', tableNobject) does not log in knex migration.
The following code is what I have tried:

// solution A
export async function up(knex: Knex) {
  const tableAobject = await knex.select('*').from('tableAobject');
  console.log('tableAobject: ', tableAobject);
}

// solution B
export async function up(knex: Knex) {
  await knex.select('*').from('tableBobject').then((tableBobject) => {
    console.log('tableBobject: ', tableBobject);
  });
}

However my terminal output is the following:

Migration Starting ...
Migrated
Migration Done.

These logs come from our migration script where we call database.migrate.latest()

My expected terminal output for the code above would be something like this:

Migration Starting ...
tableNobject: [
  {
    id: 'randomId'
    someData: 'someDataString'
    ...
  },
  ...
]
Migrated
Migration Done.

I know logging tables that you get from knex is possible because when I set up a test script outside the migration flow I can log the table without issues.

I have tried the following addition of settings:

const configA = {
  ...
  debug: true,
}

const configB = {
  ...
  log: {
    warn(message) {
      console.log(message)
    },
    error(message) {
      console.log(message)
    },
    deprecate(message) {
      console.log(message)
    },
    debug(message) {
      console.log(message)
    },
  }
}

const configC = {
  ...
  debug: true,
  log: {
    warn(message) {
      console.log(message)
    },
    error(message) {
      console.log(message)
    },
    deprecate(message) {
      console.log(message)
    },
    debug(message) {
      console.log(message)
    },
  }
};

The different settings above dont give me the logging in the terminal as I want.

The base settings (I dont know if this gives an added value):

const config = {
  client: 'postgresql',
  connection: {
    host: '127.0.0.1',
    port: '5432',
    database: 'projectName_develop',
    user: 'user',
    password: 'dev',
  },
  pool: {
    min: 2,
    max: 10,
  },
  migrations: {
    tableName: 'knex_migrations',
    directory: path.join(__dirname, 'migrations'),
  },
  seeds: {
    directory: path.join(__dirname, 'seeds'),
  },
  asyncStackTraces: true,
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So the reason why my console.log didnt log was because the migrations are TypeScript files.
I forgot to run the command: npm run build-ts-backed:watch

So the solution was easier than the issue at hand. Please remember to run your TypeScript compiler when you test in TypeScript.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda