DROP TABLE IF EXISTS game_saves;
DROP TABLE IF EXISTS users;

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  nickname VARCHAR(30) NOT NULL,
  mail VARCHAR(90) NOT NULL,
  password VARCHAR(200) NOT NULL,
  tetardcoin INT DEFAULT 0,
  firstname VARCHAR(50) NULL,
  lastname VARCHAR(50) NULL,
  super_oauth_id VARCHAR(36) NULL UNIQUE
);

CREATE TABLE game_saves (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL UNIQUE,
  game_state JSON NOT NULL,
  last_save TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  lifetime_tadpoles BIGINT DEFAULT 0,
  prestige_count INT DEFAULT 0,
  play_time_seconds INT DEFAULT 0,
  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
