Search
 
SCRIPT & CODE EXAMPLE
 

ACTIONSCRIPT

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')
};
Comment

PREVIOUS NEXT
Code Example
Actionscript :: hello world in actionscript 
Actionscript :: how to take value only from the checked checkbox 
Actionscript :: repl in pyscript 
Actionscript :: mount_osxfuse: /Users/em/mount_dev: Input/output error 
Excel :: Google Sheets How to Count the Days Between Two Dates 
Excel :: google sheets sort column by element frequency 
Excel :: excel get column number 
Excel :: excel and 
Perl :: perl post condition 
Perl :: perl variables 
Perl :: perl http request 
Pascal :: pascal readln() 
Pascal :: pascal cheat sheet pdf 
Powershell :: powershell remove node_modules 
Gdscript :: godot check if in exported version 
Clojure :: how to make a directory in clojure 
Cobol :: gatsby with yarn 
Assembly :: does assembly language use registers 
Assembly :: visual studio change assembly name 
Assembly :: fatal error: opencv2/core/version.hpp: No such file or directory 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: alphabet array 
Javascript :: javascript remover acentos 
Javascript :: javascript string to dou 
Javascript :: enable button jquery 
Javascript :: java script converting text to slug 
Javascript :: flash input 
Javascript :: jquery select checked radio button value 
Javascript :: jquery preventdefault 
Javascript :: react native position absolute center 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =