Skip to content

Commit

Permalink
enhancement: syncdb callback provides schema update status, fixes #136
Browse files Browse the repository at this point in the history
  • Loading branch information
masumsoft committed Dec 13, 2017
1 parent 8537ca0 commit 451b6a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ console.log(models.instance.Person === MyModel);
// sync the schema definition with the cassandra database table
// if the schema has not changed, the callback will fire immediately
// otherwise express-cassandra will try to migrate the schema and fire the callback afterwards
MyModel.syncDB(function(err) {
MyModel.syncDB(function(err, result) {
if (err) throw err;
// result == true if any database schema was updated
// result == false if no schema change was detected in your models
});
```

Expand Down
6 changes: 4 additions & 2 deletions src/orm/base_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ BaseModel._sync_model_definition = function f(callback) {

Promise.all(indexingTasks)
.then(() => {
callback();
// db schema was updated, so callback with true
callback(null, true);
})
.catch((err2) => {
callback(err2);
Expand Down Expand Up @@ -185,7 +186,8 @@ BaseModel._sync_model_definition = function f(callback) {
}

if (_.isEqual(normalizedModelSchema, normalizedDBSchema)) {
callback();
// no change in db was made, so callback with false
callback(null, false);
return;
}

Expand Down

0 comments on commit 451b6a0

Please sign in to comment.