Skip to content

Commit

Permalink
Data model additions for post tags, custom data and uploads
Browse files Browse the repository at this point in the history
closes TryGhost#171, closes TryGhost#314, closes TryGhost#315

- added settings for blog logo and icon
- all other settings will need to be added as needed as it's impossible to guess what the default value should be
- added tables for post tags
- added tables for post custom data
- added location column to users
- fixeed minor bug in migrations
  • Loading branch information
ErisDS committed Aug 3, 2013
1 parent f7568f6 commit 4fca917
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
17 changes: 17 additions & 0 deletions core/server/data/fixtures/002.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,24 @@ module.exports = {
"created_by": 1,
"updated_by": 1,
"type": "core"
},
{
"uuid": uuid.v4(),
"key": "logo",
"value": "",
"created_by": 1,
"updated_by": 1,
"type": "blog"
},
{
"uuid": uuid.v4(),
"key": "icon",
"value": "",
"created_by": 1,
"updated_by": 1,
"type": "blog"
}

],

roles: [],
Expand Down
62 changes: 56 additions & 6 deletions core/server/data/migration/002.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,58 @@ up = function () {

return when.all([

// TODO: Create tables or modify tables in this general area
knex.Schema.createTable('tags', function (t) {
t.increments().primary();
t.string('uuid');
t.string('name');
t.string('slug');
t.text('descripton');
t.integer('parent_id').nullable();
t.string('meta_title');
t.text('meta_description');
t.string('meta_keywords');
t.dateTime('created_at');
t.integer('created_by');
t.dateTime('updated_at').nullable();
t.integer('updated_by').nullable();
}),
knex.Schema.createTable('posts_tags', function (t) {
t.increments().primary();
t.string('uuid');
t.integer('post_id');
t.integer('tag_id');
}),
knex.Schema.createTable('custom_data', function (t) {
t.increments().primary();
t.string('uuid');
t.string('name');
t.string('slug');
t.text('value');
t.string('type').defaultTo('html');
t.string('owner').defaultTo('Ghost');
t.string('meta_title');
t.text('meta_description');
t.string('meta_keywords');
t.dateTime('created_at');
t.integer('created_by');
t.dateTime('updated_at').nullable();
t.integer('updated_by').nullable();
}),
knex.Schema.createTable('posts_custom_data', function (t) {
t.increments().primary();
t.string('uuid');
t.integer('post_id');
t.integer('custom_data_id');
}),
knex.Schema.table('users', function (t) {
t.string('location').after('bio');
})

]).then(function () {

// Once we create all of the initial tables, bootstrap any of the data

return when.all([
//knex('posts').insert(fixtures.posts),
//knex('roles').insert(fixtures.roles),
//knex('permissions').insert(fixtures.permissions),
//knex('permissions_roles').insert(fixtures.permissions_roles),
knex('settings').insert(fixtures.settings)
]);

Expand All @@ -34,7 +75,16 @@ up = function () {
};

down = function () {
return;
return when.all([
knex.Schema.dropTableIfExists("tags"),
knex.Schema.dropTableIfExists("custom_data")
]).then(function () {
// Drop the relation tables after the model tables?
return when.all([
knex.Schema.dropTableIfExists("posts_tags"),
knex.Schema.dropTableIfExists("posts_custom_data")
]);
});
};

exports.up = up;
Expand Down
9 changes: 8 additions & 1 deletion core/server/data/migration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ module.exports = {
.where('key', 'currentVersion')
.select('value')
.then(function (currentVersionSetting) {
// We are assuming here that the currentVersionSetting will
if (currentVersionSetting && currentVersionSetting.length > 0) {
currentVersionSetting = currentVersionSetting[0].value;
} else {
// we didn't get a response we understood, assume initialVersion
currentVersionSetting = initialVersion;
}

// We are assuming here that the currentVersionSetting will
// always be less than the currentVersion value.
if (currentVersionSetting === currentVersion) {
return when.resolve();
Expand Down

0 comments on commit 4fca917

Please sign in to comment.