Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
How to run knex migrations with JavaScript instead of CLI?

I have created four postresql tables. I am using nodejs with knexjs as a query builder.

I can create and execute migrations with the command line without any problems. Now I want to run migrations via Javascript. How can I proceed with this?

Here is my code: -

module.exports.runDBMigrations = async () => {
    knex.schema.hasTable(USERS_DB_NAME).then(function (exists) {
        if (!exists) {
            //Execute migrations to create users tables
        }
    })
        .catch(e => {
            console.log("Error creating tables: ", e);
        })

    knex.schema.hasTable(POSTS_DB_NAME).then(function (exists) {
        if (!exists) {
            //Execute migrations to create posts tables
        }
    })
        .catch(e => {
            console.log("Error creating tables: ", e);
        })

    knex.schema.hasTable(LIKES_DB_NAME).then(function (exists) {
        if (!exists) {
            //Execute migrations to likes users tables
        }
    })
        .catch(e => {
            console.log("Error creating tables: ", e);
        })

    knex.schema.hasTable(FOLLOWERS_DB_NAME).then(function (exists) {
        if (!exists) {
            //Execute migrations to create followers tables
        }   
    })
        .catch(e => {
            console.log("Error creating tables: ", e);
        })

}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda