-- Migration 051: Enhanced Social Media Audit
-- Adds profile completeness, activity metrics, and historical tracking
-- Date: 2026-02-06

-- Profile completeness indicators
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS has_profile_photo BOOLEAN;
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS has_cover_photo BOOLEAN;
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS has_bio BOOLEAN;
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS profile_description TEXT;

-- Activity metrics
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS posts_count_30d INTEGER;
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS posts_count_365d INTEGER;
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS last_post_date TIMESTAMP;

-- Scoring & analytics
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS posting_frequency_score INTEGER; -- 0-10
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS engagement_rate NUMERIC(5,2); -- percent
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS content_types JSONB; -- {"photos": 12, "videos": 3, "text": 5}
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS profile_completeness_score INTEGER; -- 0-100

-- Historical tracking
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS followers_history JSONB; -- [{"date": "2026-02-01", "count": 150}, ...]

-- Permissions
GRANT ALL ON TABLE company_social_media TO nordabiz_app;
