···
2
+
-- +goose StatementBegin
4
+
-- Migration: Rename community handles from .communities. to .community.
5
+
-- This aligns with AT Protocol lexicon naming conventions (singular form)
8
+
-- All atProto record types use singular form (app.bsky.feed.post, app.bsky.graph.follow)
9
+
-- This migration updates existing community handles to follow the same pattern
12
+
-- gardening.communities.coves.social -> gardening.community.coves.social
13
+
-- gaming.communities.coves.social -> gaming.community.coves.social
15
+
-- Safety: Uses REPLACE which only affects handles containing '.communities.'
16
+
-- Rollback: Available via down migration below
18
+
-- Update community handles in the communities table
20
+
SET handle = REPLACE(handle, '.communities.', '.community.')
21
+
WHERE handle LIKE '%.communities.%';
23
+
-- Verify the migration (optional - can be commented out in production)
24
+
-- This will fail if any .communities. handles remain
27
+
old_format_count INTEGER;
29
+
SELECT COUNT(*) INTO old_format_count
31
+
WHERE handle LIKE '%.communities.%';
33
+
IF old_format_count > 0 THEN
34
+
RAISE EXCEPTION 'Migration incomplete: % communities still have .communities. format', old_format_count;
37
+
RAISE NOTICE 'Migration successful: All community handles updated to .community. format';
40
+
-- +goose StatementEnd
43
+
-- +goose StatementBegin
45
+
-- Rollback: Revert handles from .community. back to .communities.
46
+
-- Only use this if you need to rollback the naming convention change
49
+
SET handle = REPLACE(handle, '.community.', '.communities.')
50
+
WHERE handle LIKE '%.community.%';
52
+
-- Verify the rollback
55
+
new_format_count INTEGER;
57
+
SELECT COUNT(*) INTO new_format_count
59
+
WHERE handle LIKE '%.community.%';
61
+
IF new_format_count > 0 THEN
62
+
RAISE EXCEPTION 'Rollback incomplete: % communities still have .community. format', new_format_count;
65
+
RAISE NOTICE 'Rollback successful: All community handles reverted to .communities. format';
68
+
-- +goose StatementEnd