From 42a6d8ab0f7f3297c3bae7d38dc22c809769b02d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 17 Jun 2024 12:25:54 -0700 Subject: [PATCH] Fix not-equals check in post aggregates update trigger (#4837) * Fix not-equals check in post aggregates update trigger Should fix #4836 * Create up.sql * Create down.sql * Update down.sql --- crates/db_schema/replaceable_schema/triggers.sql | 2 +- .../down.sql | 3 +++ .../up.sql | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 migrations/2024-06-17-160323_fix_post_aggregates_featured_local/down.sql create mode 100644 migrations/2024-06-17-160323_fix_post_aggregates_featured_local/up.sql diff --git a/crates/db_schema/replaceable_schema/triggers.sql b/crates/db_schema/replaceable_schema/triggers.sql index 98af3e546..87866e89c 100644 --- a/crates/db_schema/replaceable_schema/triggers.sql +++ b/crates/db_schema/replaceable_schema/triggers.sql @@ -486,7 +486,7 @@ BEGIN INNER JOIN old_post ON old_post.id = new_post.id AND (old_post.featured_community, old_post.featured_local) != (new_post.featured_community, - old_post.featured_local) + new_post.featured_local) WHERE post_aggregates.post_id = new_post.id; RETURN NULL; diff --git a/migrations/2024-06-17-160323_fix_post_aggregates_featured_local/down.sql b/migrations/2024-06-17-160323_fix_post_aggregates_featured_local/down.sql new file mode 100644 index 000000000..9ca12fc18 --- /dev/null +++ b/migrations/2024-06-17-160323_fix_post_aggregates_featured_local/down.sql @@ -0,0 +1,3 @@ +SELECT +; + diff --git a/migrations/2024-06-17-160323_fix_post_aggregates_featured_local/up.sql b/migrations/2024-06-17-160323_fix_post_aggregates_featured_local/up.sql new file mode 100644 index 000000000..3bb6e16b1 --- /dev/null +++ b/migrations/2024-06-17-160323_fix_post_aggregates_featured_local/up.sql @@ -0,0 +1,11 @@ +-- Fix rows that were not updated because of the old incorrect trigger +UPDATE + post_aggregates +SET + featured_local = post.featured_local +FROM + post +WHERE + post.id = post_aggregates.post_id + AND post.featured_local != post_aggregates.featured_local; +