-- Query to check all plugin versions in the database
-- Use this to verify versions are correctly configured

-- All versions ordered by release date
SELECT
    id,
    version,
    LEFT(download_url, 60) || '...' as download_url_preview,
    requires_wp_version,
    requires_php_version,
    tested_wp_version,
    is_stable,
    is_beta,
    download_count,
    released_at,
    created_at
FROM plugin_versions
ORDER BY released_at DESC, version DESC;

-- Latest stable version
SELECT
    version,
    download_url,
    download_count,
    released_at
FROM plugin_versions
WHERE is_stable = TRUE
  AND is_beta = FALSE
ORDER BY released_at DESC, version DESC
LIMIT 1;

-- Download statistics
SELECT
    version,
    download_count,
    released_at,
    EXTRACT(DAY FROM NOW() - released_at) as days_since_release,
    CASE
        WHEN download_count > 0
        THEN ROUND(download_count::numeric / EXTRACT(DAY FROM NOW() - released_at)::numeric, 2)
        ELSE 0
    END as downloads_per_day
FROM plugin_versions
WHERE is_stable = TRUE
ORDER BY released_at DESC;
