-- OAuth tokens for GA4, GSC, and GBP per project
CREATE TABLE IF NOT EXISTS project_oauth_tokens (
    id               INT AUTO_INCREMENT PRIMARY KEY,
    project_id       INT          NOT NULL,
    service          VARCHAR(20)  NOT NULL,   -- 'ga4' | 'gsc' | 'gbp'
    access_token     TEXT         NOT NULL,
    refresh_token    TEXT,
    token_expires_at DATETIME,
    account_email    VARCHAR(255),
    property_id      VARCHAR(500),  -- GA4 property ID, GSC site URL, GBP location name
    created_at       DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at       DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_project_service (project_id, service),
    INDEX idx_project_id (project_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
