lemmy/migrations/2025-08-01-000014_private-community/up.sql
Dessalines 644a448aa9
[main] Fixing active counts slow queries. (#5907) (#5917)
* [0.19] Fixing active counts slow queries. (#5907)

* Fixing active counts slow queries.

* Simplify back to str tuple

* Batch site and community updates

* Using update from temp table

* Making aggs temp table use interval name.

* Make dev setup use optimized postgres.

* Addressing PR comments.

* Use ref

* Removing system custom info from customPostgresql.conf

* Forgot to remove old scheduled tasks.

* Making sure migrations aren't missing anything from release/v0.19

Checked using git diff --diff-filter D --stat release/v0.19 migrations

* Rename all migrations to come after release/v0.19 migrations

* Add liked_at is not null check.
2025-08-09 21:57:38 +02:00

48 lines
1.3 KiB
PL/PgSQL

ALTER TYPE community_visibility
ADD value 'Private';
-- Change `community_follower.pending` to `state` enum
CREATE TYPE community_follower_state AS enum (
'Accepted',
'Pending',
'ApprovalRequired'
);
ALTER TABLE community_follower
ALTER COLUMN pending DROP DEFAULT;
CREATE OR REPLACE FUNCTION convert_follower_state (b bool)
RETURNS community_follower_state
LANGUAGE sql
IMMUTABLE PARALLEL SAFE
AS $$
SELECT
CASE WHEN b = TRUE THEN
'Pending'::community_follower_state
ELSE
'Accepted'::community_follower_state
END
$$;
ALTER TABLE community_follower
ALTER COLUMN pending TYPE community_follower_state
USING convert_follower_state (pending);
DROP FUNCTION convert_follower_state;
ALTER TABLE community_follower RENAME COLUMN pending TO state;
-- Add column for mod who approved the private community follower
-- Dont use foreign key here, otherwise joining to person table doesnt work easily
ALTER TABLE community_follower
ADD COLUMN approver_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE;
-- Enable signed fetch, necessary to fetch content in private communities
ALTER TABLE ONLY local_site
ALTER COLUMN federation_signed_fetch SET DEFAULT TRUE;
UPDATE
local_site
SET
federation_signed_fetch = TRUE;