diff --git a/core/server/data/export/index.js b/core/server/data/export/index.js index 4103e232e1..2feb006b77 100644 --- a/core/server/data/export/index.js +++ b/core/server/data/export/index.js @@ -33,7 +33,7 @@ exporter = function () { }); return when.resolve(exportData); - }, function (err) { + }).catch(function (err) { console.log('Error exporting data: ' + err); }); }); diff --git a/core/server/data/schema.js b/core/server/data/schema.js index 3b99443e50..bdbaf9d412 100644 --- a/core/server/data/schema.js +++ b/core/server/data/schema.js @@ -118,8 +118,8 @@ var db = { }, posts_tags: { id: {type: 'increments', nullable: false, primary: true}, - post_id: {type: 'integer', nullable: false, unsigned: true, references: 'id', inTable: 'posts'}, - tag_id: {type: 'integer', nullable: false, unsigned: true, references: 'id', inTable: 'tags'} + post_id: {type: 'integer', nullable: false, unsigned: true, references: 'posts.id'}, + tag_id: {type: 'integer', nullable: false, unsigned: true, references: 'tags.id'} }, apps: { id: {type: 'increments', nullable: false, primary: true}, @@ -138,7 +138,7 @@ var db = { uuid: {type: 'string', maxlength: 36, nullable: false}, key: {type: 'string', maxlength: 150, nullable: false, unique: true}, value: {type: 'text', maxlength: 65535, nullable: true}, - app_id: {type: 'integer', nullable: false, unsigned: true, references: 'id', inTable: 'apps'}, + app_id: {type: 'integer', nullable: false, unsigned: true, references: 'apps.id'}, created_at: {type: 'dateTime', nullable: false}, created_by: {type: 'integer', nullable: false}, updated_at: {type: 'dateTime', nullable: true}, @@ -150,7 +150,7 @@ var db = { key: {type: 'string', maxlength: 150, nullable: false}, value: {type: 'text', maxlength: 65535, nullable: true}, type: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'html'}, - app_id: {type: 'integer', nullable: false, unsigned: true, references: 'id', inTable: 'apps'}, + app_id: {type: 'integer', nullable: false, unsigned: true, references: 'apps.id'}, relatable_id: {type: 'integer', nullable: false, unsigned: true}, relatable_type: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'posts'}, created_at: {type: 'dateTime', nullable: false}, diff --git a/core/server/data/utils/index.js b/core/server/data/utils/index.js index bc5011ea1b..08bb17169c 100644 --- a/core/server/data/utils/index.js +++ b/core/server/data/utils/index.js @@ -32,10 +32,9 @@ function createTable(table) { if (schema[table][key].hasOwnProperty('unsigned') && schema[table][key].unsigned) { column.unsigned(); } - if (schema[table][key].hasOwnProperty('references') && schema[table][key].hasOwnProperty('inTable')) { + if (schema[table][key].hasOwnProperty('references')) { //check if table exists? column.references(schema[table][key].references); - column.inTable(schema[table][key].inTable); } if (schema[table][key].hasOwnProperty('defaultTo')) { column.defaultTo(schema[table][key].defaultTo); @@ -50,7 +49,7 @@ function deleteTable(table) { function getTablesFromSqlite3() { return knex.raw("select * from sqlite_master where type = 'table'").then(function (response) { - return _.reject(_.pluck(response[0], 'tbl_name'), function (name) { + return _.reject(_.pluck(response, 'tbl_name'), function (name) { return name === 'sqlite_sequence'; }); }); diff --git a/core/server/models/base.js b/core/server/models/base.js index 12995931b5..77ec1e065b 100644 --- a/core/server/models/base.js +++ b/core/server/models/base.js @@ -5,7 +5,8 @@ // The models are internal to Ghost, only the API and some internal functions such as migration and import/export // 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'), +var bookshelf = require('bookshelf'), + knex = require('knex'), when = require('when'), moment = require('moment'), _ = require('lodash'), @@ -20,7 +21,7 @@ var Bookshelf = require('bookshelf'), // ### ghostBookshelf // Initializes a new Bookshelf instance called ghostBookshelf, for reference elsewhere in Ghost. -ghostBookshelf = Bookshelf.ghost = Bookshelf.initialize(config().database); +ghostBookshelf = bookshelf(knex(config().database)); ghostBookshelf.client = config().database.client; // ### ghostBookshelf.Model diff --git a/package.json b/package.json index 82eb0b1432..5cb2fe1212 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "dependencies": { "bcryptjs": "0.7.10", "body-parser": "1.0.2", - "bookshelf": "0.6.8", + "bookshelf": "0.7.1", "busboy": "0.0.12", "colors": "0.6.2", "compression": "^1.0.2", @@ -46,7 +46,7 @@ "express-hbs": "0.7.10", "express-session": "1.0.4", "fs-extra": "0.8.1", - "knex": "0.5.8", + "knex": "0.6.12", "lodash": "2.4.1", "moment": "2.4.0", "morgan": "1.0.0",