RaV
RaV

Reputation: 1048

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?

Upvotes: 6

Views: 4288

Answers (1)

Jared Dykstra
Jared Dykstra

Reputation: 3626

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

Upvotes: 3

Related Questions