From e9b5533cc090a13ab6de42e3bdb144e5afd34e90 Mon Sep 17 00:00:00 2001 From: Navarjun Date: Mon, 2 Dec 2024 19:01:14 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Bulk=20adding=20tags=20created?= =?UTF-8?q?=20"duplicate"=20posts=5Ftags=20rows=20from=20editor=20posts=20?= =?UTF-8?q?page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/TryGhost/Ghost/issues/21414 The commit includes a migration which adds a unique index to posts_tags table and handles the related error when bulk adding posts. The errors are ignored because the tags user wants to add are added/exist. This respects the editor's expectation as posts have the tags as the end result. --- ...24-12-01-18-54-00-add-unique-tag-post-relationship.js | 9 +++++++++ ghost/core/package.json | 2 +- ghost/posts-service/lib/PostsService.js | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 ghost/core/core/server/data/migrations/versions/5.100/2024-12-01-18-54-00-add-unique-tag-post-relationship.js diff --git a/ghost/core/core/server/data/migrations/versions/5.100/2024-12-01-18-54-00-add-unique-tag-post-relationship.js b/ghost/core/core/server/data/migrations/versions/5.100/2024-12-01-18-54-00-add-unique-tag-post-relationship.js new file mode 100644 index 00000000000..e026ced0ff9 --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.100/2024-12-01-18-54-00-add-unique-tag-post-relationship.js @@ -0,0 +1,9 @@ +const {createIrreversibleMigration} = require('../../utils'); +const {addUnique} = require('../../../schema/commands'); +const logging = require('@tryghost/logging'); + +module.exports = createIrreversibleMigration(async (knex) => { + logging.info('Adding unique constraint to tag-post relationship'); + + await addUnique('posts_tags', ['tag_id', 'post_id'], knex); +}); diff --git a/ghost/core/package.json b/ghost/core/package.json index f42e671c5b7..f8bc29e43e9 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -1,6 +1,6 @@ { "name": "ghost", - "version": "5.101.6", + "version": "5.102.0", "description": "The professional publishing platform", "author": "Ghost Foundation", "homepage": "https://ghost.org", diff --git a/ghost/posts-service/lib/PostsService.js b/ghost/posts-service/lib/PostsService.js index 98cf806dd14..147e11bbc9b 100644 --- a/ghost/posts-service/lib/PostsService.js +++ b/ghost/posts-service/lib/PostsService.js @@ -362,7 +362,7 @@ class PostsService { })); }, []); - await options.transacting('posts_tags').insert(postTags); + await options.transacting('posts_tags').insert(postTags).onConflict().ignore(); await this.models.Post.addActions('edited', postRows.map(p => p.id), options); return {