mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Merge pull request #3321 from ErisDS/issue-2600-fin
Wrap up schema amends for 003
This commit is contained in:
commit
c9b24b0a9b
4 changed files with 23 additions and 19 deletions
|
@ -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);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue