···
+
-- +goose StatementBegin
+
-- Migration: Rename community handles from .communities. to .community.
+
-- This aligns with AT Protocol lexicon naming conventions (singular form)
+
-- All atProto record types use singular form (app.bsky.feed.post, app.bsky.graph.follow)
+
-- This migration updates existing community handles to follow the same pattern
+
-- gardening.communities.coves.social -> gardening.community.coves.social
+
-- gaming.communities.coves.social -> gaming.community.coves.social
+
-- Safety: Uses REPLACE which only affects handles containing '.communities.'
+
-- Rollback: Available via down migration below
+
-- Update community handles in the communities table
+
SET handle = REPLACE(handle, '.communities.', '.community.')
+
WHERE handle LIKE '%.communities.%';
+
-- Verify the migration (optional - can be commented out in production)
+
-- This will fail if any .communities. handles remain
+
old_format_count INTEGER;
+
SELECT COUNT(*) INTO old_format_count
+
WHERE handle LIKE '%.communities.%';
+
IF old_format_count > 0 THEN
+
RAISE EXCEPTION 'Migration incomplete: % communities still have .communities. format', old_format_count;
+
RAISE NOTICE 'Migration successful: All community handles updated to .community. format';
+
-- +goose StatementBegin
+
-- Rollback: Revert handles from .community. back to .communities.
+
-- Only use this if you need to rollback the naming convention change
+
SET handle = REPLACE(handle, '.community.', '.communities.')
+
WHERE handle LIKE '%.community.%';
+
new_format_count INTEGER;
+
SELECT COUNT(*) INTO new_format_count
+
WHERE handle LIKE '%.community.%';
+
IF new_format_count > 0 THEN
+
RAISE EXCEPTION 'Rollback incomplete: % communities still have .community. format', new_format_count;
+
RAISE NOTICE 'Rollback successful: All community handles reverted to .communities. format';