From 8b5f2789fb4fa1b320e8dd4ea2dc59a535e4edb1 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 26 Sep 2024 16:58:11 +0100 Subject: [PATCH] Added `comments.in_reply_to_id` column migration ref https://linear.app/tryghost/issue/PLG-230 - `comments.in_reply_to_id` will be used to keep a reference to the comment that the new comment was directed at - used only for replies-to-replies, will be `null` for the top-level parent and `null` for any replies directly to that parent - technically allows for infinite nesting within a parent comment thread but we won't be using that ability for now - `comments.parent_id` will be kept as it provides a useful optimisation for loading the top-level comments list - we're not using `comments.parent_id` for this to keep complexity down and avoid the need for recursive lookups --- .../2024-11-05-14-48-08-add-comments-in-reply-to-id.js | 10 ++++++++++ ghost/core/core/server/data/schema/schema.js | 1 + .../test/unit/server/data/schema/integrity.test.js | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 ghost/core/core/server/data/migrations/versions/5.100/2024-11-05-14-48-08-add-comments-in-reply-to-id.js diff --git a/ghost/core/core/server/data/migrations/versions/5.100/2024-11-05-14-48-08-add-comments-in-reply-to-id.js b/ghost/core/core/server/data/migrations/versions/5.100/2024-11-05-14-48-08-add-comments-in-reply-to-id.js new file mode 100644 index 00000000000..2538ef42573 --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.100/2024-11-05-14-48-08-add-comments-in-reply-to-id.js @@ -0,0 +1,10 @@ +const {createAddColumnMigration} = require('../../utils'); + +module.exports = createAddColumnMigration('comments', 'in_reply_to_id', { + type: 'string', + maxlength: 24, + nullable: true, + unique: false, + references: 'comments.id', + setNullDelete: true +}); diff --git a/ghost/core/core/server/data/schema/schema.js b/ghost/core/core/server/data/schema/schema.js index 45e686012a4..8d926ea81de 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -958,6 +958,7 @@ module.exports = { post_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'posts.id', cascadeDelete: true}, member_id: {type: 'string', maxlength: 24, nullable: true, unique: false, references: 'members.id', setNullDelete: true}, parent_id: {type: 'string', maxlength: 24, nullable: true, unique: false, references: 'comments.id', cascadeDelete: true}, + in_reply_to_id: {type: 'string', maxlength: 24, nullable: true, unique: false, references: 'comments.id', setNullDelete: true}, status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'published', validations: {isIn: [['published', 'hidden', 'deleted']]}}, html: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true}, edited_at: {type: 'dateTime', nullable: true}, diff --git a/ghost/core/test/unit/server/data/schema/integrity.test.js b/ghost/core/test/unit/server/data/schema/integrity.test.js index 0fca78eb751..c066a503085 100644 --- a/ghost/core/test/unit/server/data/schema/integrity.test.js +++ b/ghost/core/test/unit/server/data/schema/integrity.test.js @@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = '1110f25f639c22135b9845c72f0be7ef'; + const currentSchemaHash = 'f12341a0c74998eeb4628322fd0982fb'; const currentFixturesHash = '475f488105c390bb0018db90dce845f1'; const currentSettingsHash = '47a75e8898fab270174a0c905cb3e914'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';