2016-03-13 20:49:30 +00:00
|
|
|
// ### Reset
|
|
|
|
// Delete all tables from the database in reverse order
|
2016-10-11 14:37:11 +02:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
commands = require('../schema').commands,
|
|
|
|
schema = require('../schema').tables,
|
2016-03-13 20:49:30 +00:00
|
|
|
schemaTables = Object.keys(schema).reverse(),
|
|
|
|
reset;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* # Reset
|
|
|
|
* Deletes all the tables defined in the schema
|
|
|
|
* Uses reverse order, which ensures that foreign keys are removed before the parent table
|
|
|
|
*
|
2016-10-11 14:37:11 +02:00
|
|
|
* @TODO:
|
|
|
|
* - move to sephiroth
|
|
|
|
* - then deleting migrations table will make sense
|
|
|
|
*
|
2016-03-13 20:49:30 +00:00
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
reset = function reset() {
|
2016-10-11 14:37:11 +02:00
|
|
|
var result;
|
|
|
|
|
2016-03-13 20:49:30 +00:00
|
|
|
return Promise.mapSeries(schemaTables, function (table) {
|
|
|
|
return commands.deleteTable(table);
|
2016-10-11 14:37:11 +02:00
|
|
|
}).then(function (_result) {
|
|
|
|
result = _result;
|
|
|
|
|
|
|
|
return commands.deleteTable('migrations');
|
|
|
|
}).then(function () {
|
|
|
|
return result;
|
2016-03-13 20:49:30 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = reset;
|