0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Move creation of knex instance to config module

addresses #2170
This commit is contained in:
Harry Wolff 2014-05-14 23:28:10 -04:00
parent b69b5e7638
commit e3520feeec
4 changed files with 17 additions and 9 deletions

View file

@ -7,12 +7,14 @@ var path = require('path'),
when = require('when'),
url = require('url'),
_ = require('lodash'),
knex = require('knex'),
requireTree = require('../require-tree').readAll,
theme = require('./theme'),
configUrl = require('./url'),
ghostConfig = {},
appRoot = path.resolve(__dirname, '../../../'),
corePath = path.resolve(appRoot, 'core/');
corePath = path.resolve(appRoot, 'core/'),
knexInstance;
// Are we using sockets? Custom socket or the default?
function getSocket() {
@ -51,7 +53,14 @@ function updateConfig(config) {
// Otherwise default to default content path location
contentPath = ghostConfig.paths.contentPath || path.resolve(appRoot, 'content');
if (!knexInstance && ghostConfig.database) {
knexInstance = knex(ghostConfig.database);
}
_.merge(ghostConfig, {
database: {
knex: knexInstance
},
paths: {
'appRoot': appRoot,
'subdir': subdir,

View file

@ -4,8 +4,6 @@ var _ = require('lodash'),
fs = require('fs'),
nodefn = require('when/node'),
errors = require('../../errors'),
client = require('../../models/base').client,
knex = require('../../models/base').knex,
sequence = require('when/sequence'),
versioning = require('../versioning'),
@ -151,8 +149,10 @@ migrateUpFreshDb = function () {
// This function changes the type of posts.html and posts.markdown columns to mediumtext. Due to
// a wrong datatype in schema.js some installations using mysql could have been created using the
// data type text instead of mediumtext.
// For details see: https://github.com/TryGhost/Ghost/issues/1947
// For details see: https://github.com/TryGhost/Ghost/issues/1947
function checkMySQLPostTable() {
var knex = config().database.knex;
return knex.raw("SHOW FIELDS FROM posts where Field ='html' OR Field = 'markdown'").then(function (response) {
return _.flatten(_.map(response[0], function (entry) {
if (entry.Type.toLowerCase() !== 'mediumtext') {
@ -178,6 +178,7 @@ migrateUp = function () {
var deleteCommands,
addCommands,
oldTables,
client = config().database.client,
addColumns = [],
modifyUniCommands = [],
commands = [];
@ -244,4 +245,4 @@ module.exports = {
reset: reset,
migrateUp: migrateUp,
migrateUpFreshDb: migrateUpFreshDb
};
};

View file

@ -6,7 +6,6 @@
// accesses the models directly. All other parts of Ghost, including the blog frontend, admin UI, and apps are only
// allowed to access data via the API.
var bookshelf = require('bookshelf'),
knex = require('knex'),
when = require('when'),
moment = require('moment'),
_ = require('lodash'),
@ -21,8 +20,7 @@ var bookshelf = require('bookshelf'),
// ### ghostBookshelf
// Initializes a new Bookshelf instance called ghostBookshelf, for reference elsewhere in Ghost.
ghostBookshelf = bookshelf(knex(config().database));
ghostBookshelf.client = config().database.client;
ghostBookshelf = bookshelf(config().database.knex);
// ### ghostBookshelf.Model
// The Base Model which other Ghost objects will inherit from,

View file

@ -70,7 +70,7 @@ function updateCheckData() {
data.ghost_version = currentVersion;
data.node_version = process.versions.node;
data.env = process.env.NODE_ENV;
data.database_type = require('./models/base').client;
data.database_type = config().database.client;
data.email_transport = mailConfig && (mailConfig.options && mailConfig.options.service ? mailConfig.options.service : mailConfig.transport);
return when.settle(ops).then(function (descriptors) {