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 000000000000..e026ced0ff90 --- /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 f42e671c5b76..f8bc29e43e9a 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 98cf806dd149..147e11bbc9bd 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 {