feat: add SQL migration for relay_accounts and relay_event_queue tables (#47)
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s
Adds migration 0009_relay_access.sql with the relay_accounts and relay_event_queue DDL, completing the schema tracking for the relay whitelist feature. The Drizzle schema and all service/route code were already on main; this migration makes the table definitions explicit for environments using SQL-based migrations. Fixes #47 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
38
lib/db/migrations/0009_relay_access.sql
Normal file
38
lib/db/migrations/0009_relay_access.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
-- Migration: Relay Account Whitelist + Trust-Gated Access (#47)
|
||||
-- Adds the relay_accounts and relay_event_queue tables that back the
|
||||
-- whitelist-gated Nostr relay policy.
|
||||
|
||||
-- ── relay_accounts ────────────────────────────────────────────────────────────
|
||||
-- One row per pubkey that has been explicitly registered with the relay.
|
||||
-- Absence = "none" (default deny). FK to nostr_identities.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS relay_accounts (
|
||||
pubkey TEXT PRIMARY KEY REFERENCES nostr_identities(pubkey) ON DELETE CASCADE,
|
||||
access_level TEXT NOT NULL DEFAULT 'none', -- 'none' | 'read' | 'write'
|
||||
granted_by TEXT NOT NULL DEFAULT 'manual', -- 'manual' | 'auto-tier' | 'manual-revoked'
|
||||
granted_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
revoked_at TIMESTAMPTZ,
|
||||
notes TEXT
|
||||
);
|
||||
|
||||
-- ── relay_event_queue ─────────────────────────────────────────────────────────
|
||||
-- Holds events submitted by whitelisted non-elite accounts pending moderation.
|
||||
-- Elite accounts bypass this table; their events are injected directly into strfry.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS relay_event_queue (
|
||||
event_id TEXT PRIMARY KEY,
|
||||
pubkey TEXT NOT NULL REFERENCES nostr_identities(pubkey) ON DELETE CASCADE,
|
||||
kind INTEGER NOT NULL,
|
||||
raw_event TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'pending', -- 'pending' | 'approved' | 'rejected' | 'auto_approved' | 'flagged'
|
||||
reviewed_by TEXT, -- 'timmy_ai' | 'admin'
|
||||
review_reason TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
decided_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_relay_event_queue_pubkey
|
||||
ON relay_event_queue(pubkey);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_relay_event_queue_status
|
||||
ON relay_event_queue(status);
|
||||
Reference in New Issue
Block a user