我发现有两种方法可以在迁移文件中编写knex迁移。创建knex迁移
exports.up = function (knex) {
return knex.schema
.createTableIfNotExists('foo', function (table) {
table.increments('id').unique();
table.string('foo1');
table.string('foo2');
})
.createTableIfNotExists('bar', function (table) {
table.increments('bar1');
table.string('bar2').index();
});
或者
exports.up = function (knex) {
return Promise.all([
knex.schema.createTableIfNotExists('foo', function (table) {
table.increments('id').unique();
table.string('foo1');
table.string('foo2');
}),
knex.schema.createTableIfNotExists('bar', function (table) {
table.increments('bar1');
table.string('bar2').index();
})
]);
}
哪一个是做的正确方法吗?