-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 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
- Loading branch information
Showing
24 changed files
with
144 additions
and
97 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,43 @@ | ||
var Promise = require('bluebird'), | ||
versioning = require('./versioning'), | ||
populate = require('../migration/populate'), | ||
errors = require('./../../errors'); | ||
Sephiroth = require('../sephiroth'), | ||
db = require('../db'), | ||
config = require('./../../config'), | ||
errors = require('./../../errors'), | ||
models = require('./../../models'), | ||
versioning = require('./../../data/schema/versioning'), | ||
logging = require('./../../logging'), | ||
fixtures = require('../migration/fixtures'), | ||
sephiroth = new Sephiroth({database: config.get('database')}); | ||
|
||
/** | ||
* @TODO: | ||
* - move this file out of schema folder | ||
* - this file right now takes over seeding, which get's fixed in one of the next PR's | ||
* - remove fixtures.populate | ||
* - remove versioning.setDatabaseVersion(transaction); | ||
* - remove models.Settings.populateDefaults(_.merge({}, {transacting: transaction}, modelOptions)); | ||
* - key: migrations-kate | ||
*/ | ||
module.exports = function bootUp() { | ||
/** | ||
* @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 | ||
*/ | ||
return versioning | ||
.getDatabaseVersion() | ||
.catch(function errorHandler(err) { | ||
if (err instanceof errors.DatabaseNotPopulatedError) { | ||
return populate(); | ||
} | ||
var modelOptions = { | ||
context: { | ||
internal: true | ||
} | ||
}; | ||
|
||
return Promise.reject(err); | ||
return sephiroth.utils.isDatabaseOK() | ||
.then(function () { | ||
return models.Settings.populateDefaults(modelOptions); | ||
}) | ||
.then(function () { | ||
return versioning.setDatabaseVersion(db.knex); | ||
}) | ||
.then(function () { | ||
return fixtures.populate(logging, modelOptions); | ||
}) | ||
.catch(function (err) { | ||
return Promise.reject(new errors.GhostError({ | ||
err: 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
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
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
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
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
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
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
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
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
Oops, something went wrong.