diff --git a/replaceable_schema.sql b/replaceable_schema.sql index 61a2e5664..d784f2d07 100644 --- a/replaceable_schema.sql +++ b/replaceable_schema.sql @@ -215,24 +215,22 @@ BEGIN AS $$ BEGIN -- Update aggregates for target, then update aggregates for target's creator - WITH target_diff ( - creator_id, score -) AS ( UPDATE - %1$s_aggregates AS target_aggregates + WITH target_diff AS ( UPDATE + %1$s_aggregates SET - score = score + diff.upvotes - diff.downvotes, upvotes = upvotes + diff.upvotes, downvotes = downvotes + diff.downvotes, controversy_rank = controversy_rank ((upvotes + diff.upvotes)::numeric, (downvotes + diff.downvotes)::numeric) + (score, upvotes, downvotes, controversy_rank) = (score + diff.upvotes - diff.downvotes, upvotes + diff.upvotes, downvotes + diff.downvotes, controversy_rank ((upvotes + diff.upvotes)::numeric, (downvotes + diff.downvotes)::numeric)) FROM ( SELECT - target_id, sum(count_diff) FILTER (WHERE score = 1) AS upvotes, sum(count_diff) FILTER (WHERE score <> 1) AS downvotes FROM r.combine_transition_tables () - GROUP BY target_id) AS diff + %1$s_id, sum(count_diff) FILTER (WHERE score = 1) AS upvotes, sum(count_diff) FILTER (WHERE score <> 1) AS downvotes FROM r.combine_transition_tables () + GROUP BY %1$s_id) AS diff WHERE - target_aggregates.comment_id = diff.target_id + %1$s_aggregates.%1 $ s_id = diff.%1$s_id RETURNING - %2$s, diff.upvotes - diff.downvotes) + %2$s AS creator_id, diff.upvotes - diff.downvotes AS score) UPDATE person_aggregates SET - %1$s_score = %1$s_score + diff.score FROM ( + %1$s_score = %1$s_score + diff.sum FROM ( SELECT creator_id, sum(score) FROM target_diff GROUP BY creator_id) AS diff diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index 14e4b3011..e320372cd 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -3,7 +3,9 @@ export PGDATA="$PWD/dev_pgdata" export PGHOST=$PWD export PGUSER=postgres -export LEMMY_DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD" +export DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD" +export LEMMY_DATABASE_URL=$DATABASE_URL +export PGDATABASE=lemmy # If cluster exists, stop the server and delete the cluster if [ -d $PGDATA ] @@ -21,6 +23,5 @@ initdb --username=postgres --auth=trust --no-instructions pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$PWD" > /dev/null # Setup database -psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;" -psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;" -export PGDATABASE=lemmy +PGDATABASE=postgres psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;" +PGDATABASE=postgres psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;"