CREATE DATABASE IF NOT EXISTS vprmini_simple DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE vprmini_simple;

--jakob

DROP TABLE IF EXISTS characters;
DROP TABLE IF EXISTS sessions;
DROP TABLE IF EXISTS users;

-- user für login
CREATE TABLE users (
  user_id INT AUTO_INCREMENT PRIMARY KEY,
  username VARCHAR(40) NOT NULL UNIQUE,
  pass_hash VARCHAR(255) NOT NULL
);

-- charaktere sind unique und gehören zu einem user
CREATE TABLE characters (
  character_id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL,
  name VARCHAR(50) NOT NULL,
  CONSTRAINT fk_char_user FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE,
  CONSTRAINT ux_user_char UNIQUE(user_id, name)
);

-- session 
CREATE TABLE sessions (
  session_id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(100) NOT NULL
);
