From 7aff1966194eeca5ee279dc6245e9c46e249cda2 Mon Sep 17 00:00:00 2001 From: Bretton Date: Fri, 17 Oct 2025 17:54:50 -0700 Subject: [PATCH] feat(db): add community_blocks table with proper DID validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create migration for community blocking feature with: - user_did and community_did with widened regex validation - blocked_at timestamp for chronological ordering - record_uri and record_cid for atProto federation - Unique constraint on (user_did, community_did) pairs - Indexes for efficient queries DID regex pattern ^did:(plc|web):[a-zA-Z0-9._:%-]+$ supports: - Uppercase and lowercase letters - Dots for did:web domains (e.g., did:web:coves.social) - Hyphens, underscores, colons, percent signs per DID spec - Anchored to end for strict matching Fixes: PR review comment #1 (P0 - Critical) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../009_create_community_blocks_table.sql | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 internal/db/migrations/009_create_community_blocks_table.sql diff --git a/internal/db/migrations/009_create_community_blocks_table.sql b/internal/db/migrations/009_create_community_blocks_table.sql new file mode 100644 index 0000000..27c2df8 --- /dev/null +++ b/internal/db/migrations/009_create_community_blocks_table.sql @@ -0,0 +1,27 @@ +-- +goose Up +CREATE TABLE community_blocks ( + id SERIAL PRIMARY KEY, + user_did TEXT NOT NULL CHECK (user_did ~ '^did:(plc|web):[a-zA-Z0-9._:%-]+$'), + community_did TEXT NOT NULL CHECK (community_did ~ '^did:(plc|web):[a-zA-Z0-9._:%-]+$'), + blocked_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- AT-Proto metadata (block record lives in user's repo) + -- These are required for atProto record verification and federation + record_uri TEXT NOT NULL, -- atProto record identifier (at://user_did/social.coves.community.block/rkey) + record_cid TEXT NOT NULL, -- Content address (critical for verification) + + UNIQUE(user_did, community_did) +); + +-- Indexes for efficient queries +CREATE INDEX idx_blocks_user ON community_blocks(user_did); +CREATE INDEX idx_blocks_community ON community_blocks(community_did); +CREATE INDEX idx_blocks_user_community ON community_blocks(user_did, community_did); +CREATE INDEX idx_blocks_blocked_at ON community_blocks(blocked_at); + +-- +goose Down +DROP INDEX IF EXISTS idx_blocks_blocked_at; +DROP INDEX IF EXISTS idx_blocks_user_community; +DROP INDEX IF EXISTS idx_blocks_community; +DROP INDEX IF EXISTS idx_blocks_user; +DROP TABLE IF EXISTS community_blocks; -- 2.51.2