-- 044_microdao_activity.sql
-- Migration: Create microdao_activity table for news/updates/events feed

CREATE TABLE IF NOT EXISTS microdao_activity (
    id              UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    microdao_slug   TEXT NOT NULL REFERENCES microdaos(slug) ON DELETE CASCADE,
    kind            TEXT NOT NULL CHECK (kind IN ('post', 'event', 'update')),
    title           TEXT,
    body            TEXT NOT NULL,
    author_agent_id TEXT NULL,
    author_name     TEXT NULL,
    created_at      TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_microdao_activity_microdao_created_at
    ON microdao_activity (microdao_slug, created_at DESC);

COMMENT ON TABLE microdao_activity IS 'Activity feed for MicroDAO: posts, events, updates';
COMMENT ON COLUMN microdao_activity.kind IS 'Type: post (news), event (announcement), update (status change)';
COMMENT ON COLUMN microdao_activity.author_agent_id IS 'Optional reference to agent who created this activity';
COMMENT ON COLUMN microdao_activity.author_name IS 'Fallback author name if agent_id is not set';

