CREATE TABLE IF NOT EXISTS public_events (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    community_id UUID REFERENCES communities(id) ON DELETE CASCADE,
    actor_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
    plugin_name VARCHAR(100),
    event_type VARCHAR(100) NOT NULL,
    payload JSONB NOT NULL DEFAULT '{}',
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_public_events_community ON public_events(community_id);
CREATE INDEX IF NOT EXISTS idx_public_events_created ON public_events(created_at);
CREATE INDEX IF NOT EXISTS idx_public_events_type ON public_events(event_type);
