all files / lib/waterline/adapter/sync/strategies/ drop.js

27.27% Statements 3/11
0% Branches 0/4
0% Functions 0/3
30% Lines 3/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                                                       
/**
 * Module dependencies
 */
 
var _ = require('lodash');
var getRelations = require('../../../utils/getRelations');
 
 
/**
 * Drop and recreate collection
 *
 * @param  {Function} cb
 */
 
module.exports = function drop(cb) {
  var self = this;
 
  // Refuse to run this migration strategy in production.
  if (process.env.NODE_ENV === 'production') {
    return cb(new Error('`migrate: "drop"` strategy is not supported in production, please change to `migrate: "safe"`.'));
  }
 
  // Find any junctionTables that reference this collection
  // var relations = getRelations({
  //   schema: self.query.waterline.schema,
  //   parentCollection: self.collection
  // });
 
  // Pass along relations to the drop method
  // console.log('Dropping ' + self.collection);
  this.drop(function afterDrop(err, data) {
    if (err) return cb(err);
 
    self.define(function() {
      cb.apply(null, Array.prototype.slice.call(arguments));
    });
  });
};