Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Use Knex createTable workaround (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jun 21, 2017
1 parent c510870 commit 8a96c49
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions generators/service/templates/model/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
module.exports = function (app) {
const db = app.get('knexClient');

db.schema.createTableIfNotExists('<%= kebabName %>', table => {
table.increments('id');
table.string('text');
}).then(
() => console.log('Updated <%= kebabName %> table'),
e => console.error('Error updating <%= kebabName %> table', e)
);
db.schema.hasTable('<%= kebabName %>').then(exists => {
if(!exists) {
db.schema.createTable('<%= kebabName %>', table => {
table.increments('id');
table.string('text');
}).then(
() => console.log('Updated <%= kebabName %> table'),
e => console.error('Error updating <%= kebabName %> table', e)
);
}
});


return db;
};

0 comments on commit 8a96c49

Please sign in to comment.