-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π¨ β± Cleanup / optimise the server.init() function (#7985)
refs #2182 * π₯ Remove unused options from server init - this is left over from old code and is now unused * π¨ Move knex-migrator check to db health - Move complex check function into own module - Call module from server/index.js - This just improves the readability of server/index.js * π₯ Remove old comments - These comments all make no sense now! * π¨ β± Move model init out of promise chain - Model.init() does not return a promise - Therefore, we can move it to the top of the init function, outside of the promise change - This should be a minor optimisation, and again improves readability /clarity of what's happening * β¨βοΈ Move DBHash init / first run to Settings model - this structure is left over from when we had code we executed on the first run of Ghost - the implementation used the API to initialise one setting before populateDefaults is called - this had lots of dependencies - the whole model, API, and permissions structure had to be initialised for it to work - the new implementation is simpler, it captures the dbHash getting initialised during populateDefaults() - it also adds an event, so we can do first-run code later if we really want to (or maybe apps can?!) - perhaps this is hiding behaviour, and there's a nicer way to do it, but populateDefaults seems like a sane place to populate a default setting π * β± Optimise require order so config is first - the first require to config will cause the files to be read etc - this ensures that it happens early, and isn't confusingly timed as part of loading a different module * π¨ Simplify settings model changes
- Loading branch information
Showing
3 changed files
with
63 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var KnexMigrator = require('knex-migrator'), | ||
config = require('../../config'), | ||
errors = require('../../errors'), | ||
models = require('../../models'); | ||
|
||
module.exports.check = function healthCheck() { | ||
var knexMigrator = new KnexMigrator({ | ||
knexMigratorFilePath: config.get('paths:appRoot') | ||
}); | ||
|
||
return knexMigrator.isDatabaseOK() | ||
.catch(function (outerErr) { | ||
if (outerErr.code === 'DB_NOT_INITIALISED') { | ||
throw outerErr; | ||
} | ||
|
||
// CASE: migration table does not exist, figure out if database is compatible | ||
return models.Settings.findOne({key: 'databaseVersion', context: {internal: true}}) | ||
.then(function (response) { | ||
// CASE: no db version key, database is compatible | ||
if (!response) { | ||
throw outerErr; | ||
} | ||
|
||
throw new errors.DatabaseVersionError({ | ||
message: 'Your database version is not compatible with Ghost 1.0.0 Alpha (master branch)', | ||
context: 'Want to keep your DB? Use Ghost < 1.0.0 or the "stable" branch. Otherwise please delete your DB and restart Ghost.', | ||
help: 'More information on the Ghost 1.0.0 Alpha at https://support.ghost.org/v1-0-alpha' | ||
}); | ||
}) | ||
.catch(function (err) { | ||
// CASE: settings table does not exist | ||
if (err.errno === 1 || err.errno === 1146) { | ||
throw outerErr; | ||
} | ||
|
||
throw err; | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters