-- Migration: Add play_count column to tracks table
-- This resolves the "column play_count does not exist" error

-- Add play_count column to tracks table
ALTER TABLE tracks ADD COLUMN IF NOT EXISTS play_count BIGINT DEFAULT 0;

-- Initialize play_count with values from total_streams
UPDATE tracks SET play_count = total_streams WHERE play_count = 0;

-- Create index for better query performance
CREATE INDEX IF NOT EXISTS idx_tracks_play_count ON tracks(play_count DESC);

-- Create index for ringtone queries (if columns exist)
CREATE INDEX IF NOT EXISTS idx_tracks_ringtone_enabled ON tracks(ringtone_enabled) WHERE ringtone_enabled = true;

-- Add comment
COMMENT ON COLUMN tracks.play_count IS 'Total number of times this track has been played';
