Can migrations be used with bookshelf.js?

I am trying to use migrations using knex and bookshelf, and so far this is my code, this 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 running:

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

But no changes have occurred in my database. Any ideas how I can make it work?

+4
source share
1 answer

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

Source: https://habr.com/ru/post/1615099/


All Articles