diff --git a/core/server/data/migration/commands.js b/core/server/data/migration/commands.js index 3880539ff0..4d9afff7be 100644 --- a/core/server/data/migration/commands.js +++ b/core/server/data/migration/commands.js @@ -44,7 +44,7 @@ addColumnCommands = function addColumnCommands(table, columns) { return _.map(addColumns, function (column) { return function () { logInfo('Adding column: ' + table + '.' + column); - utils.addColumn(table, column); + return utils.addColumn(table, column); }; }); }; diff --git a/core/server/data/schema.js b/core/server/data/schema.js index b1d200c861..111b0f5434 100644 --- a/core/server/data/schema.js +++ b/core/server/data/schema.js @@ -103,6 +103,8 @@ var db = { name: {type: 'string', maxlength: 150, nullable: false}, slug: {type: 'string', maxlength: 150, nullable: false, unique: true}, description: {type: 'string', maxlength: 200, nullable: true}, + image: {type: 'text', maxlength: 2000, nullable: true}, + hidden: {type: 'bool', nullable: false, defaultTo: false, validations: {'isIn': [[0, 1, false, true]]}}, parent_id: {type: 'integer', nullable: true}, meta_title: {type: 'string', maxlength: 150, nullable: true}, meta_description: {type: 'string', maxlength: 200, nullable: true}, @@ -148,7 +150,7 @@ var db = { 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'}, - active: {type: 'bool', nullable: false, defaultTo: true, validations: {'isIn': [[false, true]]}}, + active: {type: 'bool', nullable: false, defaultTo: true, validations: {'isIn': [[0, 1, false, true]]}}, created_at: {type: 'dateTime', nullable: false}, created_by: {type: 'integer', nullable: false}, updated_at: {type: 'dateTime', nullable: true}, @@ -187,8 +189,8 @@ function isPost(jsonData) { } function isTag(jsonData) { - return jsonData.hasOwnProperty('name') && jsonData.hasOwnProperty('slug') - && jsonData.hasOwnProperty('description') && jsonData.hasOwnProperty('parent_id'); + return jsonData.hasOwnProperty('name') && jsonData.hasOwnProperty('slug') && + jsonData.hasOwnProperty('description') && jsonData.hasOwnProperty('parent_id'); } module.exports.tables = db; diff --git a/core/server/data/utils/index.js b/core/server/data/utils/index.js index 46ea3af853..c7b832cb30 100644 --- a/core/server/data/utils/index.js +++ b/core/server/data/utils/index.js @@ -6,36 +6,38 @@ var _ = require('lodash'), function addTableColumn(tablename, table, columnname) { - var column; + var column, + columnSpec = schema[tablename][columnname]; + // creation distinguishes between text with fieldtype, string with maxlength and all others - if (schema[tablename][columnname].type === 'text' && schema[tablename][columnname].hasOwnProperty('fieldtype')) { - column = table[schema[tablename][columnname].type](columnname, schema[tablename][columnname].fieldtype); - } else if (schema[tablename][columnname].type === 'string' && schema[tablename][columnname].hasOwnProperty('maxlength')) { - column = table[schema[tablename][columnname].type](columnname, schema[tablename][columnname].maxlength); + if (columnSpec.type === 'text' && columnSpec.hasOwnProperty('fieldtype')) { + column = table[columnSpec.type](columnname, columnSpec.fieldtype); + } else if (columnSpec.type === 'string' && columnSpec.hasOwnProperty('maxlength')) { + column = table[columnSpec.type](columnname, columnSpec.maxlength); } else { - column = table[schema[tablename][columnname].type](columnname); + column = table[columnSpec.type](columnname); } - if (schema[tablename][columnname].hasOwnProperty('nullable') && schema[tablename][columnname].nullable === true) { + if (columnSpec.hasOwnProperty('nullable') && columnSpec.nullable === true) { column.nullable(); } else { column.notNullable(); } - if (schema[tablename][columnname].hasOwnProperty('primary') && schema[tablename][columnname].primary === true) { + if (columnSpec.hasOwnProperty('primary') && columnSpec.primary === true) { column.primary(); } - if (schema[tablename][columnname].hasOwnProperty('unique') && schema[tablename][columnname].unique) { + if (columnSpec.hasOwnProperty('unique') && columnSpec.unique) { column.unique(); } - if (schema[tablename][columnname].hasOwnProperty('unsigned') && schema[tablename][columnname].unsigned) { + if (columnSpec.hasOwnProperty('unsigned') && columnSpec.unsigned) { column.unsigned(); } - if (schema[tablename][columnname].hasOwnProperty('references')) { + if (columnSpec.hasOwnProperty('references')) { //check if table exists? - column.references(schema[tablename][columnname].references); + column.references(columnSpec.references); } - if (schema[tablename][columnname].hasOwnProperty('defaultTo')) { - column.defaultTo(schema[tablename][columnname].defaultTo); + if (columnSpec.hasOwnProperty('defaultTo')) { + column.defaultTo(columnSpec.defaultTo); } } diff --git a/core/test/utils/api.js b/core/test/utils/api.js index 83075b525e..f913810ce3 100644 --- a/core/test/utils/api.js +++ b/core/test/utils/api.js @@ -13,7 +13,7 @@ var url = require('url'), 'updated_by', 'published_at', 'published_by', 'page', 'author', 'tags', 'fields'], settings: ['settings', 'meta'], setting: ['id', 'uuid', 'key', 'value', 'type', 'created_at', 'created_by', 'updated_at', 'updated_by'], - tag: ['id', 'uuid', 'name', 'slug', 'description', 'parent', + tag: ['id', 'uuid', 'name', 'slug', 'description', 'parent', 'image', 'hidden', 'meta_title', 'meta_description', 'created_at', 'created_by', 'updated_at', 'updated_by'], theme: ['uuid', 'name', 'version', 'active'], user: ['id', 'uuid', 'name', 'slug', 'email', 'image', 'cover', 'bio', 'website',