Skip to content

Commit d646736

Browse files
authored
Merge pull request #460 from dahlia/fix/legacy-remote-quotes
Avoid backfilling remote quote policies
2 parents 27071dd + 5852320 commit d646736

3 files changed

Lines changed: 33 additions & 16 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Version 0.9.0
77
To be released.
88

99
- Added [FEP-044f] quote authorization and policy support on top of the
10-
Mastodon-compatible quote APIs. [[#457], [#459]]
10+
Mastodon-compatible quote APIs. [[#457], [#459], [#460]]
1111

1212
- Added persistent quote states for `pending`, `accepted`, `rejected`,
1313
`revoked`, and `unauthorized` quotes, plus quote target and
@@ -100,6 +100,7 @@ To be released.
100100
[#457]: https://github.com/fedify-dev/hollo/pull/457
101101
[#458]: https://github.com/fedify-dev/hollo/pull/458
102102
[#459]: https://github.com/fedify-dev/hollo/pull/459
103+
[#460]: https://github.com/fedify-dev/hollo/pull/460
103104

104105

105106
Version 0.8.1

drizzle/0086_quote_controls.sql

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,29 @@ CREATE TYPE "public"."quote_approval_policy" AS ENUM(
1313
ALTER TABLE "posts" ADD COLUMN "quote_target_iri" text;--> statement-breakpoint
1414
ALTER TABLE "posts" ADD COLUMN "quote_state" "quote_state";--> statement-breakpoint
1515
ALTER TABLE "posts" ADD COLUMN "quote_authorization_iri" text;--> statement-breakpoint
16-
ALTER TABLE "posts" ADD COLUMN "quote_approval_policy" "quote_approval_policy" DEFAULT 'public' NOT NULL;--> statement-breakpoint
16+
-- Add this column as nullable and without an immediate default. Existing
17+
-- remote posts did not have quote policy data before this migration, and
18+
-- defaulting every row to 'public' would make legacy remote posts
19+
-- indistinguishable from cached FEP-044f public-policy posts. The following
20+
-- backfill intentionally touches only local posts, where Hollo owns the quote
21+
-- policy and can derive it from existing visibility.
22+
ALTER TABLE "posts" ADD COLUMN "quote_approval_policy" "quote_approval_policy";--> statement-breakpoint
1723
UPDATE "posts" AS "post"
1824
SET
1925
"quote_target_iri" = "target"."iri",
2026
"quote_state" = 'accepted'
2127
FROM "posts" AS "target"
2228
WHERE "post"."quote_target_id" = "target"."id";--> statement-breakpoint
2329
UPDATE "posts"
24-
SET "quote_approval_policy" = 'nobody'
25-
WHERE "visibility" IN ('private', 'direct');
30+
SET "quote_approval_policy" = CASE
31+
WHEN "posts"."visibility" IN ('private', 'direct')
32+
THEN 'nobody'::"quote_approval_policy"
33+
ELSE 'public'::"quote_approval_policy"
34+
END
35+
FROM "account_owners"
36+
WHERE "posts"."actor_id" = "account_owners"."id";--> statement-breakpoint
37+
-- Set the default only after the local backfill. New local posts keep the
38+
-- public default, while persisted remote posts can still explicitly store NULL
39+
-- when no FEP-044f interaction policy was observed.
40+
ALTER TABLE "posts"
41+
ALTER COLUMN "quote_approval_policy" SET DEFAULT 'public';
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
-- An earlier draft of 0086 added "quote_approval_policy" as
2+
-- DEFAULT 'public' NOT NULL, then this migration dropped NOT NULL and rewrote
3+
-- cached remote public rows to NULL. That was too expensive on large "posts"
4+
-- tables and still could not distinguish old legacy remote posts from cached
5+
-- FEP-044f posts that really advertised a public quote policy.
6+
--
7+
-- Since 0086 and 0087 are unreleased and will be applied together, 0086 now
8+
-- creates the final nullable column shape directly, backfills only local posts,
9+
-- and leaves existing remote rows NULL. Keep this cheap DROP NOT NULL for
10+
-- databases that already applied the earlier 0086 draft but not 0087, so they
11+
-- can still accept NULL for newly persisted legacy remote posts.
112
ALTER TABLE "posts"
2-
ALTER COLUMN "quote_approval_policy" DROP NOT NULL;--> statement-breakpoint
3-
-- Migration 0086 defaulted every existing post to 'public', so cached remote
4-
-- legacy posts and cached remote FEP-044f public posts are indistinguishable
5-
-- here. Prefer preserving legacy interoperability for old cached remote
6-
-- posts; limited FEP policies such as 'followers' and 'nobody' remain intact.
7-
UPDATE "posts"
8-
SET "quote_approval_policy" = NULL
9-
WHERE "quote_approval_policy" = 'public'
10-
AND "actor_id" NOT IN (
11-
SELECT "id"
12-
FROM "account_owners"
13-
);
13+
ALTER COLUMN "quote_approval_policy" DROP NOT NULL;

0 commit comments

Comments
 (0)