Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗️ Added meta fields to collections table #17769

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ghost/collections/src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ export class Collection {
type: data.type || 'manual',
filter: data.filter || null,
featureImage: data.feature_image || null,
ogImage: data.og_image || null,
ogTitle: data.og_title || null,
ogDescription: data.og_description || null,
twitterImage: data.twitter_image || null,
twitterTitle: data.twitter_title || null,
twitterDescription: data.twitter_description || null,
metaTitle: data.meta_title || null,
metaDescription: data.meta_description || null,
codeinjectionHead: data.codeinjection_head || null,
codeinjectionFoot: data.codeinjection_foot || null,
canonicalUrl: data.canonical_url || null,
createdAt: Collection.validateDateField(data.created_at, 'created_at'),
updatedAt: Collection.validateDateField(data.updated_at, 'updated_at'),
deleted: data.deleted || false,
Expand Down
39 changes: 39 additions & 0 deletions ghost/collections/src/CollectionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ type CollectionPostListItemDTO = {
title: string;
featured: boolean;
featured_image?: string;
og_image?: string;
og_title?: string;
og_description?: string;
twitter_image?: string;
twitter_title?: string;
twitter_description?: string;
meta_title?: string;
meta_description?: string;
codeinjection_head?: string;
codeinjection_foot?: string;
canonical_url?: string;
accent_color?: string;
created_at: Date;
updated_at: Date;
published_at: Date,
Expand All @@ -67,6 +79,18 @@ type ManualCollection = {
description?: string;
feature_image?: string;
filter?: null;
og_image?: string;
og_title?: string;
og_description?: string;
twitter_image?: string;
twitter_title?: string;
twitter_description?: string;
meta_title?: string;
meta_description?: string;
codeinjection_head?: string;
codeinjection_foot?: string;
canonical_url?: string;
accent_color?: string;
deletable?: boolean;
};

Expand All @@ -77,6 +101,18 @@ type AutomaticCollection = {
slug?: string;
description?: string;
feature_image?: string;
og_image?: string;
og_title?: string;
og_description?: string;
twitter_image?: string;
twitter_title?: string;
twitter_description?: string;
meta_title?: string;
meta_description?: string;
codeinjection_head?: string;
codeinjection_foot?: string;
canonical_url?: string;
accent_color?: string;
deletable?: boolean;
};

Expand Down Expand Up @@ -244,6 +280,9 @@ export class CollectionsService {
type: data.type,
filter: data.filter,
featureImage: data.feature_image,
ogImage: data.og_image,
ogTitle: data.og_title,

deletable: data.deletable
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const {combineNonTransactionalMigrations, createAddColumnMigration} = require('../../utils');

module.exports = combineNonTransactionalMigrations(
createAddColumnMigration('collections', 'og_image', {
type: 'string',
maxlength: 2000,
nullable: true
}),
createAddColumnMigration('collections', 'og_title', {
type: 'string',
maxlength: 300,
nullable: true
}),
createAddColumnMigration('collections', 'og_description', {
type: 'string',
maxlength: 500,
nullable: true
}),
createAddColumnMigration('collections', 'twitter_image', {
type: 'string',
maxlength: 2000,
nullable: true
}),
createAddColumnMigration('collections', 'twitter_title', {
type: 'string',
maxlength: 300,
nullable: true
}),
createAddColumnMigration('collections', 'twitter_description', {
type: 'string',
maxlength: 500,
nullable: true
}),
createAddColumnMigration('collections', 'meta_title', {
type: 'string',
maxlength: 2000,
nullable: true,
validations: {
isLength: {
max: 300
}
}
}),
createAddColumnMigration('collections', 'meta_description', {
type: 'string',
maxlength: 2000,
nullable: true,
validations: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has no effect in a migration, it's used by bookshelf models only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm. true. we do use this syntax in other migrations too. I think it's here to match the syntax in schema to dot?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I've seen it in other migrations, AFAIK they aren't there for a reason though, just misunderstanding or copy/paste errors!

IMO it will cause confusion by being there but 🤷

isLength: {
max: 500
}
}
}),
createAddColumnMigration('collections', 'codeinjection_head', {
type: 'text',
maxlength: 65535,
nullable: true
}),
createAddColumnMigration('collections', 'codeinjection_foot', {
type: 'text',
maxlength: 65535,
nullable: true
}),
createAddColumnMigration('collections', 'canonical_url', {
type: 'string',
maxlength: 2000,
nullable: true
}),
createAddColumnMigration('collections', 'accent_color', {
type: 'string',
maxlength: 50,
nullable: true
})
);

12 changes: 12 additions & 0 deletions ghost/core/core/server/data/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,18 @@ module.exports = {
type: {type: 'string', maxlength: 50, nullable: false},
filter: {type: 'text', maxlength: 1000000000, nullable: true},
feature_image: {type: 'string', maxlength: 2000, nullable: true},
og_image: {type: 'string', maxlength: 2000, nullable: true},
og_title: {type: 'string', maxlength: 300, nullable: true},
og_description: {type: 'string', maxlength: 500, nullable: true},
twitter_image: {type: 'string', maxlength: 2000, nullable: true},
twitter_title: {type: 'string', maxlength: 300, nullable: true},
twitter_description: {type: 'string', maxlength: 500, nullable: true},
meta_title: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 300}}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind having a validation here that doesn't match the column definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a "soft limit" which is set in all "meta_title" fields. More context here. My understanding it that we ha put a larger field size of 2000 chars to have a buffer just in case we ever need to increase the length of the field. In reality it's been 6 years and there was no need for increase. If we are concerned about optimal field sizes, might be a good idea to trim all meta_title fields to a length of 300 in Ghost v6 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I see

Yeah that seems weird we don't do that with any other fields!

meta_description: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 500}}},
codeinjection_head: {type: 'text', maxlength: 65535, nullable: true},
codeinjection_foot: {type: 'text', maxlength: 65535, nullable: true},
canonical_url: {type: 'string', maxlength: 2000, nullable: true},
accent_color: {type: 'string', maxlength: 50, nullable: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
Expand Down
2 changes: 1 addition & 1 deletion ghost/core/test/unit/server/data/schema/integrity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = 'ad44bf95fee71a878704bff2a313a583';
const currentSchemaHash = '092ae8a5146ff101cc24761731fdb712';
const currentFixturesHash = '1803057343a6afa7b50f1dabbc21424d';
const currentSettingsHash = 'dd0e318627ded65e41f188fb5bdf5b74';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
Expand Down