Documentation Tutorials

Migrations (MYSQL)

js-web can handle all table creations.

The table creations are possible by using the table function found on the migration.mysql object.

const db = require('js-web').migration.mysql

Following fieldtypes are supported by the js-web migrations

/*
  Fieldtypes:
  id (auto increment),
  string,
  int,
  datetime,
  bool,
  text
 */

Table(tablename,tableDefinitions)

const db = require('js-web').migration.mysql

const migrate = async _ => {
  await db.table('users',{
    id: 'id',
    name: 'string',
    created: 'datetime'
  })
  await db.table('pets',{
    id: 'id',
    name: 'string',
    user_id: 'int',
    created: 'datetime'
  })
  process.exit()
}

migrate()

Create tables

Run the js file, and the database will be corrected to match the table definitions.

node db.js