mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-01 16:51:21 +00:00
Update replaceable_schema.sql
This commit is contained in:
parent
4b9f4ce043
commit
1ff9c6f06c
1 changed files with 30 additions and 30 deletions
|
@ -46,13 +46,13 @@ BEGIN
|
||||||
RETURN QUERY
|
RETURN QUERY
|
||||||
SELECT
|
SELECT
|
||||||
-1 AS count_diff,
|
-1 AS count_diff,
|
||||||
*
|
old_table AS affected_row
|
||||||
FROM
|
FROM
|
||||||
old_table
|
old_table
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
1 AS count_diff,
|
1 AS count_diff,
|
||||||
*
|
new_table AS affected_row
|
||||||
FROM
|
FROM
|
||||||
new_table;
|
new_table;
|
||||||
ELSIF (TG_OP = 'INSERT') THEN
|
ELSIF (TG_OP = 'INSERT') THEN
|
||||||
|
@ -144,13 +144,13 @@ BEGIN
|
||||||
controversy_rank = controversy_rank ((a.upvotes + diff.upvotes)::numeric, (a.downvotes + diff.downvotes)::numeric)
|
controversy_rank = controversy_rank ((a.upvotes + diff.upvotes)::numeric, (a.downvotes + diff.downvotes)::numeric)
|
||||||
FROM (
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
thing_id,
|
(thing_like).thing_id,
|
||||||
sum(count_diff) FILTER (WHERE score = 1) AS upvotes,
|
sum(count_diff) FILTER (WHERE (thing_like).score = 1) AS upvotes,
|
||||||
sum(count_diff) FILTER (WHERE score != 1) AS downvotes
|
sum(count_diff) FILTER (WHERE (thing_like).score != 1) AS downvotes
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables ()
|
r.combine_transition_tables () AS (count_diff bigint, thing_like thing_like)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
thing_id) AS diff
|
(thing_like).thing_id) AS diff
|
||||||
WHERE
|
WHERE
|
||||||
a.thing_id = diff.thing_id
|
a.thing_id = diff.thing_id
|
||||||
RETURNING
|
RETURNING
|
||||||
|
@ -191,19 +191,19 @@ CREATE FUNCTION r.parent_aggregates_from_comment ()
|
||||||
BEGIN
|
BEGIN
|
||||||
WITH comment_group AS (
|
WITH comment_group AS (
|
||||||
SELECT
|
SELECT
|
||||||
post_id,
|
(comment).post_id,
|
||||||
creator_id,
|
(comment).creator_id,
|
||||||
local,
|
(comment).local,
|
||||||
sum(count_diff) AS comments
|
sum(count_diff) AS comments
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables ()
|
r.combine_transition_tables () AS (count_diff bigint, comment comment)
|
||||||
WHERE
|
WHERE
|
||||||
NOT (deleted
|
NOT ((comment).deleted
|
||||||
OR removed)
|
OR (comment).removed)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
GROUPING SETS (post_id,
|
GROUPING SETS ((comment)post_id,
|
||||||
creator_id,
|
(comment).creator_id,
|
||||||
local)
|
(comment).local)
|
||||||
),
|
),
|
||||||
unused_person_aggregates_update_result AS (
|
unused_person_aggregates_update_result AS (
|
||||||
UPDATE
|
UPDATE
|
||||||
|
@ -293,19 +293,19 @@ CREATE FUNCTION r.parent_aggregates_from_post ()
|
||||||
BEGIN
|
BEGIN
|
||||||
WITH post_group AS (
|
WITH post_group AS (
|
||||||
SELECT
|
SELECT
|
||||||
community_id,
|
(post).community_id,
|
||||||
creator_id,
|
(post).creator_id,
|
||||||
local,
|
(post).local,
|
||||||
sum(count_diff) AS posts
|
sum(count_diff) AS posts
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables ()
|
r.combine_transition_tables () AS (count_diff bigint, post post)
|
||||||
WHERE
|
WHERE
|
||||||
NOT (deleted
|
NOT ((post).deleted
|
||||||
OR removed)
|
OR (post).removed)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
GROUPING SETS (community_id,
|
GROUPING SETS ((post).community_id,
|
||||||
creator_id,
|
(post).creator_id,
|
||||||
local)
|
(post).local)
|
||||||
),
|
),
|
||||||
unused_person_aggregates_update_result AS (
|
unused_person_aggregates_update_result AS (
|
||||||
UPDATE
|
UPDATE
|
||||||
|
@ -353,11 +353,11 @@ BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
sum(change_diff) AS communities
|
sum(change_diff) AS communities
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables ()
|
r.combine_transition_tables () AS (count_diff bigint, community community)
|
||||||
WHERE
|
WHERE
|
||||||
local
|
(community).local
|
||||||
AND NOT (deleted
|
AND NOT ((community).deleted
|
||||||
OR removed)) AS diff;
|
OR (community).removed)) AS diff;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END
|
END
|
||||||
$$;
|
$$;
|
||||||
|
@ -377,7 +377,7 @@ BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
sum(change_diff) AS users
|
sum(change_diff) AS users
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables ()
|
r.combine_transition_tables () AS (count_diff bigint,
|
||||||
WHERE
|
WHERE
|
||||||
local) AS diff;
|
local) AS diff;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
|
|
Loading…
Reference in a new issue