Remove un-rectify-able changes
This commit is contained in:
parent
2de33d4da5
commit
52eb72d94f
|
@ -172,15 +172,19 @@ Change.prototype.rectify = function(cb) {
|
||||||
|
|
||||||
async.parallel(tasks, function(err) {
|
async.parallel(tasks, function(err) {
|
||||||
if(err) return cb(err);
|
if(err) return cb(err);
|
||||||
change.save(cb);
|
if(change.prev === Change.UNKNOWN) {
|
||||||
|
// this occurs when a record of a change doesn't exist
|
||||||
|
// and its current revision is null (not found)
|
||||||
|
change.remove(cb);
|
||||||
|
} else {
|
||||||
|
change.save(cb);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateRevision(cb) {
|
function updateRevision(cb) {
|
||||||
// get the current revision
|
// get the current revision
|
||||||
change.currentRevision(function(err, rev) {
|
change.currentRevision(function(err, rev) {
|
||||||
if(err) return Change.handleError(err, cb);
|
if(err) return Change.handleError(err, cb);
|
||||||
change.debug('updating revision ('+ rev +')');
|
|
||||||
// deleted
|
|
||||||
if(rev) {
|
if(rev) {
|
||||||
// avoid setting rev and prev to the same value
|
// avoid setting rev and prev to the same value
|
||||||
if(currentRev !== rev) {
|
if(currentRev !== rev) {
|
||||||
|
@ -196,10 +200,9 @@ Change.prototype.rectify = function(cb) {
|
||||||
} else if(!change.prev) {
|
} else if(!change.prev) {
|
||||||
change.debug('ERROR - could not determing prev');
|
change.debug('ERROR - could not determing prev');
|
||||||
change.prev = Change.UNKNOWN;
|
change.prev = Change.UNKNOWN;
|
||||||
return cb(new Error('could not determine the previous rev for '
|
|
||||||
+ change.modelId));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
change.debug('updated revision (was ' + currentRev + ')');
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -493,8 +496,9 @@ Change.prototype.getModel = function(callback) {
|
||||||
*
|
*
|
||||||
* **Note: call `conflict.fetch()` to get the `target` and `source` models.
|
* **Note: call `conflict.fetch()` to get the `target` and `source` models.
|
||||||
*
|
*
|
||||||
* @param {*} sourceModelId
|
* @param {*} modelId
|
||||||
* @param {*} targetModelId
|
* @param {DataModel} SourceModel
|
||||||
|
* @param {DataModel} TargetModel
|
||||||
* @property {ModelClass} source The source model instance
|
* @property {ModelClass} source The source model instance
|
||||||
* @property {ModelClass} target The target model instance
|
* @property {ModelClass} target The target model instance
|
||||||
*/
|
*/
|
||||||
|
@ -570,9 +574,9 @@ Conflict.prototype.changes = function(cb) {
|
||||||
], done);
|
], done);
|
||||||
|
|
||||||
function getSourceChange(cb) {
|
function getSourceChange(cb) {
|
||||||
conflict.SourceChange.findOne({
|
conflict.SourceChange.findOne({where: {
|
||||||
modelId: conflict.sourceModelId
|
modelId: conflict.modelId
|
||||||
}, function(err, change) {
|
}}, function(err, change) {
|
||||||
if(err) return cb(err);
|
if(err) return cb(err);
|
||||||
sourceChange = change;
|
sourceChange = change;
|
||||||
cb();
|
cb();
|
||||||
|
@ -580,9 +584,9 @@ Conflict.prototype.changes = function(cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTargetChange(cb) {
|
function getTargetChange(cb) {
|
||||||
conflict.TargetChange.findOne({
|
conflict.TargetChange.findOne({where: {
|
||||||
modelId: conflict.targetModelId
|
modelId: conflict.modelId
|
||||||
}, function(err, change) {
|
}}, function(err, change) {
|
||||||
if(err) return cb(err);
|
if(err) return cb(err);
|
||||||
targetChange = change;
|
targetChange = change;
|
||||||
cb();
|
cb();
|
||||||
|
|
|
@ -767,7 +767,8 @@ DataModel.createUpdates = function(deltas, cb) {
|
||||||
if(err) return cb(err);
|
if(err) return cb(err);
|
||||||
if(!inst) {
|
if(!inst) {
|
||||||
console.error('missing data for change:', change);
|
console.error('missing data for change:', change);
|
||||||
return callback();
|
return cb && cb(new Error('missing data for change: '
|
||||||
|
+ change.modelId));
|
||||||
}
|
}
|
||||||
if(inst.toObject) {
|
if(inst.toObject) {
|
||||||
update.data = inst.toObject();
|
update.data = inst.toObject();
|
||||||
|
|
Loading…
Reference in New Issue