Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this possible to use migrations with bookshelf.js?

I am trying to use migrations with knex and bookshelf, and so far thats my code, it is an example from the bookshelf documentation:

exports.up = function(knex, Promise) {
  return knex.schema.createTable('books', function(table) {
    table.increments('id').primary();
    table.string('name');
  }).createTable('summaries', function(table) {
    table.increments('id').primary();
    table.string('details');
    table.integer('book_id').unique().references('books.id');
  });
};

I tried run:

knex migrate:make my_migration_name
knex migrate:latest
knex migrate:rollback

But not a single change in my database. Any ideas how I can get it working?

like image 407
RaV Avatar asked Oct 18 '22 22:10

RaV


1 Answers

Use .then() to create a chain of promises:

exports.up = function(knex, Promise) {
  return knex.schema.createTable('books', function(table) {
    table.increments('id').primary();
    table.string('name');
  }).then(function() {
    return createTable('summaries', function(table) {
      table.increments('id').primary();
      table.string('details');
      table.integer('book_id').unique().references('books.id');
    });
  });
};
like image 190
Jared Dykstra Avatar answered Oct 22 '22 03:10

Jared Dykstra