create extension if not exists "uuid-ossp";
create extension if not exists "citext";

create schema forum;

create table forum.user (
  user_uuid uuid primary key default uuid_generate_v4(),
  user_email text not null unique,
  user_username text not null unique,
  user_password_hash text not null,
  user_is_admin boolean default false
);

create table forum.site (
  site_uuid uuid primary key default uuid_generate_v4(),
  site_title text not null,
  site_base_url text not null,
  site_theme text not null default 'internal',
  site_singleton boolean default true,
  constraint only_one_site check (site_singleton)
);

create table forum.board (
  board_uuid uuid primary key default uuid_generate_v4(),
  board_site uuid not null references forum.site (site_uuid),
  board_title text not null,
  board_description text not null
);

create table forum.thread (
  thread_uuid uuid primary key default uuid_generate_v4(),
  thread_board uuid not null references forum.board (board_uuid),
  thread_title text not null
);

create table forum.post (
  post_uuid uuid primary key default uuid_generate_v4(),
  post_thread uuid not null references forum.thread (thread_uuid),
  post_contents text not null,
  post_author uuid not null references forum.user (user_uuid)
);
