Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!