CREATE TABLE scores (
  id INT AUTO_INCREMENT PRIMARY KEY,
  game_id VARCHAR(100) NOT NULL,
  play_id VARCHAR(64) NOT NULL,
  player VARCHAR(24) NOT NULL,
  score INTEGER NOT NULL,
  time_ms INTEGER NOT NULL,
  moves INTEGER NOT NULL,
  played_at BIGINT NOT NULL,
  approved BOOLEAN NOT NULL DEFAULT TRUE,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CONSTRAINT scores_play_id_unique UNIQUE (play_id)
);

CREATE INDEX idx_scores_leaderboard
ON scores (game_id, approved, score DESC, time_ms ASC, moves ASC);
