-- Initial builds + forums tables
CREATE TABLE IF NOT EXISTS builds (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(160) NOT NULL,
  game VARCHAR(80) NOT NULL,
  class_name VARCHAR(80) NOT NULL,
  patch VARCHAR(40) DEFAULT NULL,
  summary VARCHAR(240) DEFAULT NULL,
  skills TEXT,
  gear TEXT,
  author VARCHAR(80) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS build_comments (
  id INT AUTO_INCREMENT PRIMARY KEY,
  build_id INT NOT NULL,
  author VARCHAR(80) NOT NULL,
  body TEXT NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX (build_id),
  CONSTRAINT fk_build_comment FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS forum_threads (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(160) NOT NULL,
  game VARCHAR(80) NOT NULL,
  tag VARCHAR(40) DEFAULT NULL,
  body TEXT NOT NULL,
  author VARCHAR(80) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS forum_posts (
  id INT AUTO_INCREMENT PRIMARY KEY,
  thread_id INT NOT NULL,
  author VARCHAR(80) NOT NULL,
  body TEXT NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX (thread_id),
  CONSTRAINT fk_thread_post FOREIGN KEY (thread_id) REFERENCES forum_threads(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
