-- Add is_valid column to fcm_tokens table to track token validity
-- Run this SQL in phpMyAdmin or MySQL command line

ALTER TABLE fcm_tokens 
ADD COLUMN IF NOT EXISTS is_valid TINYINT(1) DEFAULT 1 AFTER token,
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER is_valid;

-- Create index for faster queries
CREATE INDEX IF NOT EXISTS idx_is_valid ON fcm_tokens(is_valid);
CREATE INDEX IF NOT EXISTS idx_phone ON fcm_tokens(phone);

-- Optional: Clean up invalid tokens older than 30 days
-- DELETE FROM fcm_tokens WHERE is_valid = 0 AND updated_at < DATE_SUB(NOW(), INTERVAL 30 DAY);
