2016-09-20 14:44:07 +01:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
versioning = require('./versioning'),
|
2016-09-27 12:18:45 +02:00
|
|
|
populate = require('../migration/populate'),
|
2016-09-20 14:44:07 +01:00
|
|
|
errors = require('./../../errors');
|
|
|
|
|
|
|
|
module.exports = function bootUp() {
|
2016-10-06 15:50:55 +02:00
|
|
|
/**
|
|
|
|
* @TODO:
|
|
|
|
* - 1. call is check if tables are populated
|
|
|
|
* - 2. call is check if db is seeded
|
|
|
|
*
|
|
|
|
* These are the calls Ghost will make to find out if the db is in OK state!
|
|
|
|
* These check's will have nothing to do with the migration module!
|
|
|
|
* Ghost will not touch the migration module at all.
|
|
|
|
*
|
|
|
|
* Example code:
|
|
|
|
* models.Settings.findOne({key: 'databasePopulated'})
|
|
|
|
* If not, throw error and tell user what to do (ghost db-init)!
|
|
|
|
*
|
|
|
|
* versioning.getDatabaseVersion() - not sure about that yet.
|
|
|
|
* This will read the database version of the settings table!
|
|
|
|
* If not, throw error and tell user what to do (ghost db-seed)!
|
|
|
|
*
|
|
|
|
* @TODO:
|
|
|
|
* - remove return populate() -> belongs to db init
|
|
|
|
* - key: migrations-kate
|
|
|
|
*/
|
2016-09-20 14:44:07 +01:00
|
|
|
return versioning
|
|
|
|
.getDatabaseVersion()
|
2016-10-06 15:50:55 +02:00
|
|
|
.catch(function errorHandler(err) {
|
2016-10-06 14:27:35 +02:00
|
|
|
if (err instanceof errors.DatabaseNotPopulatedError) {
|
2016-09-27 12:18:45 +02:00
|
|
|
return populate();
|
2016-09-20 14:44:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(err);
|
|
|
|
});
|
|
|
|
};
|