He creado cuatro tablas postresql. Estoy usando nodejs con knexjs como generador de consultas.
Puedo crear y ejecutar migraciones con la línea de comandos sin ningún problema. Ahora quiero ejecutar migraciones a través de Javascript. ¿Cómo puedo proceder con esto?
Aquí está mi código: -
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); }) }