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() {
|
|
|
|
return versioning
|
|
|
|
.getDatabaseVersion()
|
|
|
|
.then(function successHandler(result) {
|
|
|
|
if (!/^alpha/.test(result)) {
|
|
|
|
// This database was not created with Ghost alpha, and is not compatible
|
|
|
|
throw new errors.DatabaseVersion(
|
|
|
|
'Your database version is not compatible with Ghost 1.0.0 Alpha (master branch)',
|
|
|
|
'Want to keep your DB? Use Ghost < 1.0.0 or the "stable" branch. Otherwise please delete your DB and restart Ghost',
|
|
|
|
'More information on the Ghost 1.0.0 Alpha at https://support.ghost.org/v1-0-alpha'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// We don't use .catch here, as it would catch the error from the successHandler
|
|
|
|
function errorHandler(err) {
|
|
|
|
if (err instanceof errors.DatabaseNotPopulated) {
|
2016-09-27 12:18:45 +02:00
|
|
|
return populate();
|
2016-09-20 14:44:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(err);
|
|
|
|
});
|
|
|
|
};
|