

-- ---- 3. Live score (har venue no ek j current row) ----
CREATE TABLE IF NOT EXISTS live_score (
    venue_id     INT PRIMARY KEY DEFAULT 1,
    player       VARCHAR(120) DEFAULT '',
    mode         VARCHAR(30)  DEFAULT '',
    score        INT DEFAULT 0,
    wicket       INT DEFAULT 0,
    overs        VARCHAR(10) DEFAULT '0.0',
    fours        INT DEFAULT 0,
    sixes        INT DEFAULT 0,
    strike_rate  DECIMAL(6,2) DEFAULT 0,
    run_rate     DECIMAL(6,2) DEFAULT 0,
    target       INT DEFAULT 0,
    high_score   INT DEFAULT 0,
    high_by      VARCHAR(120) DEFAULT '',
    updated_at   TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;

INSERT INTO live_score (venue_id) VALUES (1)
ON DUPLICATE KEY UPDATE venue_id = venue_id;

-- ---- 5. Top scores / leaderboard ----
CREATE TABLE IF NOT EXISTS top_scores (
    id        INT AUTO_INCREMENT PRIMARY KEY,
    venue_id  INT NOT NULL DEFAULT 1,
    name      VARCHAR(120) NOT NULL,
    mobile    VARCHAR(15) DEFAULT '',
    score     INT NOT NULL DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_ls (venue_id, score)
) ENGINE=InnoDB;
