From 5c929c4952509bdb5fae6ab41ae83611876325aa Mon Sep 17 00:00:00 2001 From: Martin Kraft Date: Wed, 13 Jul 2022 10:19:59 -0400 Subject: [PATCH] Coalesce migration of Reactions.ChannelId to '' if Post does not exist. (#20643) Co-authored-by: Mattermod --- db/migrations/mysql/000089_add-channelid-to-reaction.up.sql | 2 +- db/migrations/postgres/000089_add-channelid-to-reaction.up.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrations/mysql/000089_add-channelid-to-reaction.up.sql b/db/migrations/mysql/000089_add-channelid-to-reaction.up.sql index e1864b938b..11e24a8b99 100644 --- a/db/migrations/mysql/000089_add-channelid-to-reaction.up.sql +++ b/db/migrations/mysql/000089_add-channelid-to-reaction.up.sql @@ -14,7 +14,7 @@ EXECUTE addColumnIfNotExists; DEALLOCATE PREPARE addColumnIfNotExists; -UPDATE Reactions SET ChannelId = (select ChannelId from Posts where Posts.Id = Reactions.PostId) WHERE ChannelId=""; +UPDATE Reactions SET ChannelId = COALESCE((select ChannelId from Posts where Posts.Id = Reactions.PostId), '') WHERE ChannelId=""; SET @preparedStatement = (SELECT IF( diff --git a/db/migrations/postgres/000089_add-channelid-to-reaction.up.sql b/db/migrations/postgres/000089_add-channelid-to-reaction.up.sql index 2affd3fcde..36cc156626 100644 --- a/db/migrations/postgres/000089_add-channelid-to-reaction.up.sql +++ b/db/migrations/postgres/000089_add-channelid-to-reaction.up.sql @@ -1,3 +1,3 @@ ALTER TABLE reactions ADD COLUMN IF NOT EXISTS channelid varchar(26) NOT NULL DEFAULT ''; -UPDATE reactions SET channelid = (select channelid from posts where posts.id = reactions.postid) WHERE channelid=''; +UPDATE reactions SET channelid = COALESCE((select channelid from posts where posts.id = reactions.postid), '') WHERE channelid=''; CREATE INDEX IF NOT EXISTS idx_reactions_channel_id on reactions (channelid);