-- T0281: Create Track Like System Database Model
-- Create table track_likes with user_id, track_id, created_at and unique index

-- Table track_likes
CREATE TABLE IF NOT EXISTS track_likes (
    id BIGSERIAL PRIMARY KEY,
    user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    track_id BIGINT NOT NULL REFERENCES tracks(id) ON DELETE CASCADE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Indexes
CREATE INDEX IF NOT EXISTS idx_track_likes_user ON track_likes(user_id);
CREATE INDEX IF NOT EXISTS idx_track_likes_track ON track_likes(track_id);

-- Unique constraint to prevent duplicate likes (user can only like a track once)
CREATE UNIQUE INDEX IF NOT EXISTS idx_track_likes_unique ON track_likes(user_id, track_id);

