Ghost/core/server/data/migration/reset.js
Katharina Irrgang 9fad7f1d69 use migration runner for init db (#7502)
refs #7489

* 🎨  protect error when creating owner
* 🎨  reset migration table
- temporary solution, see TODO's
* 🎨  use sephiroth in bootUp script
- do not populate the database
- ask sephiroth for database state
- do seeding manually (this will be removed in next seeding PR)
* 🎨  rewrite createTableIfNotExists because it causes error when running twice
- see knex issue
- hasTable and createTable
- indexes can cause trouble when calling them twice
* 🎨  tests: populate db in test env
- when forking db
- when starting ghost()
- this basically affects only the functional tests
* 🎨  server spec test adaption
- we now throw an error when database is not populated, instead of populating the database
* 🎨   migration spec adaption
- reset database now deletes migration table
- we will move the reset script into sephiroth and then we make it pretty
* 🎨  error creation adaption in bootUp
* 🎨  fixes
- sephiroth error handling
- fix tests
2016-10-11 13:37:11 +01:00

35 lines
874 B
JavaScript

// ### Reset
// Delete all tables from the database in reverse order
var Promise = require('bluebird'),
commands = require('../schema').commands,
schema = require('../schema').tables,
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
*
* @TODO:
* - move to sephiroth
* - then deleting migrations table will make sense
*
* @returns {Promise<*>}
*/
reset = function reset() {
var result;
return Promise.mapSeries(schemaTables, function (table) {
return commands.deleteTable(table);
}).then(function (_result) {
result = _result;
return commands.deleteTable('migrations');
}).then(function () {
return result;
});
};
module.exports = reset;