Answers for "knex create new migration"

0

knex create new migration

knex migrate:make nameOfMigration
Posted by: Guest on October-25-2021
0

knex.js migration execute

$ knex migrate:latest
Posted by: Guest on October-18-2021
1

move records from table to another using knex migration

// modified by Emmanuel Mahuni to use async/await more readable code
exports.up = async function(knex) {
 	await knex.schema.createTable('table_b', t => {
      t.string('col_a')
      t.string('col_b')
    })
  
    await knex.schema.createTable('table_c', t => {
      t.string('col_c')
      t.string('col_d')
    })
  
    let rows = await knex('table_a').select('col_a', 'col_b')
    await knex('table_b').insert(rows)
    
  	rows = await knex('table_a').select('col_c', 'col_d')
    await knex('table_c').insert(rows)
  
    await knex.schema.dropTableIfExists('table_a'))
};

exports.down = async function(knex) {
  await knex.schema.createTable('table_a', t => {
      t.string('col_a')
      t.string('col_b')
      t.string('col_c')
      t.string('col_d')
    })
  
  let rows = await knex('table_b').select('col_a', 'col_b')
  await knex('table_a').insert(rows)
  
  rows = await knex('table_c').select('col_c', 'col_d')
  await knex('table_a').insert(rows)
  
  await knex.schema.dropTableIfExists('table_b')
  await knex.schema.dropTableIfExists('table_c')
};
Posted by: Guest on November-13-2020
0

knex.js migration create

$ knex migrate:make --stub 

# or

$ knex migrate:make --stub
Posted by: Guest on October-18-2021

Code answers related to "knex create new migration"

Browse Popular Code Answers by Language