-- Token Cleanup Script
-- Membersihkan token lama dan memastikan hanya token valid yang ada

-- 1. Hapus semua token lama yang tidak valid
UPDATE "Luv2_user" 
SET session_token = NULL 
WHERE session_token IS NOT NULL 
AND session_token != ''
AND session_token NOT IN (
    'xQMnzKlCPlDE9NRrWUs0AzDfTgrCp83OjH8CvACmlkobDClXjAGzc9ZfCObS',
    '3xyCueSxxvD2r801iqTDz6FxKNdOmqtihzJJyc1CgVqdEVL5sfGp6yE4Hmtn'
);

-- 2. Pastikan token valid tetap ada dan active
UPDATE "Luv2_user" 
SET active = 'Y' 
WHERE session_token IN (
    'xQMnzKlCPlDE9NRrWUs0AzDfTgrCp83OjH8CvACmlkobDClXjAGzc9ZfCObS',
    '3xyCueSxxvD2r801iqTDz6FxKNdOmqtihzJJyc1CgVqdEVL5sfGp6yE4Hmtn'
);

-- 3. Cek status token yang ada
SELECT 
    username, 
    session_token, 
    active, 
    created_at,
    LENGTH(session_token) as token_length
FROM "Luv2_user" 
WHERE session_token IS NOT NULL 
AND session_token != ''
ORDER BY created_at DESC;

-- 4. Cek total token valid
SELECT 
    COUNT(*) as total_valid_tokens,
    COUNT(CASE WHEN active = 'Y' THEN 1 END) as active_tokens,
    COUNT(CASE WHEN active != 'Y' THEN 1 END) as inactive_tokens
FROM "Luv2_user" 
WHERE session_token IS NOT NULL 
AND session_token != '';
