generator-loopback-kenx-migration
Version:
Generate kenx migration from loopback models
21 lines (18 loc) • 881 B
JavaScript
exports.up = function(knex, Promise) {
return knex.schema.createTable('<%= tableName %>', (table) => {
<% if (idInjection) { %>
table
.bigInteger('id')
.primary()
<% }; %>
<% modelSchemaList.forEach(function(row){ %>
table
.<%= typeof modelSchema[row] === 'string' ? (modelSchema[row] === 'number'?'integer':modelSchema[row]) : (modelSchema[row].type === 'number'?'integer':toLowerCase(modelSchema[row].type)) %>('<%= row==="ACL"?"acl":toDbCase(row) %>')
<% if (typeof modelSchema[row] !== 'string' && !!modelSchema[row].required) { %>.notNullable()<% }; %>
<% if (typeof modelSchema[row] !== 'string' && modelSchema[row].id) { %>.primary()<% }; %>
<% }); %>
});
};
exports.down = function(knex, Promise) {
return knex.schema.dropTable('<%= tableName %>')
};