T
T
tarasikgoga2017-07-05 00:24:22
PostgreSQL
tarasikgoga, 2017-07-05 00:24:22

How to make a rolling migration to knex.js?

I am writing a migration using knex.js and the question is how to write it correctly for several tables, for example, there is a nav table and for it the migration will look like this

exports.up = function(knex, Promise) {
  return knex.schema.createTable('nav', (table) => {
    table.increments();
    table.string('name').unique().notNullable();
    table.string('path').unique().notNullable();
  }).then(() => {
    return knex('nav').insert([
      { name: 'A', path: 'A' },
      { name: 'B', path: 'BB' },
      { name: 'C', path: 'CCC' },
      { name: 'D', path: 'DDDD' }
    ])
  })
};

but what if I need to create a second table 'subNav' where the row (row) should be dependent on the id from the first table? How to create multiple tables sequentially?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Manakov, 2017-07-05
@gogolor

So write the code for creating the second table in the following then

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question