GUIPSS

Migrations examples with node-db-migrate

Posted on: 2018-08-23

Create / Remove Table


exports.up = db =>
  db.createTable(`book`, {
    columns : {
      id : {
        type       : `text`,
        primaryKey : true,
      },
      title : {
        type: `text`,
      },
      createdAt : {
        type : `datetime`,
      },
      updatedAt : {
        type : `datetime`,
      },
    },
  })
;

exports.down = db =>
  db.dropTable(`book`)
;

Add Column / Remove Column


exports.up = db =>
  db.addColumn(`user`, `node`, { type : `text` })
;

exports.down = db =>
  db.removeColumn(`user`, `node`)
;