knex-runner
Tiny library for building a knex schema and running migrations
Knex commands run asynchronously, so you must write some boilerplate code to ensure that all of your tables are created in the correct order. This library is that boilerplate code.
Installation
$ npm install knex-runner
Usage
var runner = require; runner;
This builds your schema, in order, and then runs any pending migrations.
schema
must be an array of knex
database command functions, like so:
var createOrdersTable =
Important: as illustrated above, your commands must resolve a promise at some point. Manufacture a promise and resolve it if your function does not need to perform any
knex
operations under certain circumstances.
Parameters
knexOptions:
knex database connection and configuration object
schema:
array of knex database command functions
callback:
(optional) function that should accept an error
argument that will be invoked once the schema/migrations are fully run
log:
(optional, defaults to true) log events to the console