-- Migration 977: Track when a user was promoted to the 'creator' role (v1.0.6)
-- Follow-up to the v1.0.5 audit: upload was gated on role=creator with no
-- self-service path. v1.0.6 adds POST /api/v1/users/me/upgrade-creator; this
-- column records when that one-way transition happened so audit + analytics
-- can distinguish organic creators from legacy role assignments.
--
-- NULL = user has never been self-promoted (either still role='user' or
-- was assigned a higher role by an admin without going through the flow).

ALTER TABLE public.users
    ADD COLUMN IF NOT EXISTS promoted_to_creator_at TIMESTAMPTZ NULL;

CREATE INDEX IF NOT EXISTS idx_users_promoted_to_creator_at
    ON public.users(promoted_to_creator_at)
    WHERE promoted_to_creator_at IS NOT NULL;
