
CREATE TABLE anime (
  id integer NOT NULL,
  ann_id integer[],
  type anime_type,
  year smallint,
  title_romaji text,
  title_kanji text,
  mal_id integer[],
  PRIMARY KEY(id)
);

CREATE TABLE chars (
  id text NOT NULL,
  image text,
  bloodt blood_type NOT NULL,
  cup_size cup_size NOT NULL,
  sex char_sex NOT NULL,
  spoil_sex char_sex,
  gender char_gender,
  spoil_gender char_gender,
  main text,
  main_spoil smallint NOT NULL,
  s_bust smallint NOT NULL,
  s_waist smallint NOT NULL,
  s_hip smallint NOT NULL,
  birthday smallint NOT NULL,
  height smallint NOT NULL,
  weight smallint,
  age smallint,
  description text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE chars_alias (
  id text NOT NULL,
  spoil smallint NOT NULL,
  name text NOT NULL,
  latin text,
  PRIMARY KEY(id, name)
);

CREATE TABLE chars_names (
  id text NOT NULL,
  lang language NOT NULL,
  name text NOT NULL,
  latin text,
  PRIMARY KEY(id, lang)
);

CREATE TABLE chars_traits (
  id text NOT NULL,
  tid text NOT NULL,
  spoil smallint NOT NULL,
  lie boolean NOT NULL,
  PRIMARY KEY(id, tid)
);

CREATE TABLE chars_vns (
  id text NOT NULL,
  vid text NOT NULL,
  rid text NULL,
  role char_role NOT NULL,
  spoil smallint NOT NULL
);

CREATE TABLE docs (
  id text NOT NULL,
  title text NOT NULL,
  content text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE drm (
  id integer,
  disc boolean NOT NULL,
  cdkey boolean NOT NULL,
  activate boolean NOT NULL,
  alimit boolean NOT NULL,
  account boolean NOT NULL,
  online boolean NOT NULL,
  cloud boolean NOT NULL,
  physical boolean NOT NULL,
  name text NOT NULL,
  description text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE engines (
  id integer,
  name text NOT NULL,
  description text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE entry_meta (
  id text,
  created date NOT NULL,
  lastmod date NOT NULL,
  revision smallint NOT NULL,
  num_edits smallint NOT NULL,
  num_users smallint NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE extlinks (
  id integer,
  site extlink_site NOT NULL,
  value text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE image_votes (
  id text NOT NULL,
  uid text,
  date date NOT NULL,
  sexual smallint NOT NULL CHECK(sexual >= 0 AND sexual <= 2),
  violence smallint NOT NULL CHECK(violence >= 0 AND violence <= 2),
  ignore boolean NOT NULL
);

CREATE TABLE images (
  id text NOT NULL,
  width smallint NOT NULL,
  height smallint NOT NULL,
  c_votecount smallint NOT NULL,
  c_sexual_avg smallint NOT NULL,
  c_sexual_stddev smallint NOT NULL,
  c_violence_avg smallint NOT NULL,
  c_violence_stddev smallint NOT NULL,
  c_weight smallint NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE producers (
  id text NOT NULL,
  type producer_type NOT NULL,
  lang language NOT NULL,
  name text NOT NULL,
  latin text,
  alias text NOT NULL,
  description text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE producers_extlinks (
  id text NOT NULL,
  link integer NOT NULL,
  PRIMARY KEY(id, link)
);

CREATE TABLE producers_relations (
  id text NOT NULL,
  pid text NOT NULL,
  relation producer_relation NOT NULL,
  PRIMARY KEY(id, pid)
);

CREATE TABLE quotes (
  id text NOT NULL,
  vid text NOT NULL,
  cid text,
  score smallint NOT NULL,
  quote text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE releases (
  id text NOT NULL,
  gtin bigint NOT NULL,
  olang language NOT NULL,
  released integer NOT NULL,
  voiced smallint NOT NULL,
  reso_x smallint NOT NULL,
  reso_y smallint NOT NULL,
  minage smallint,
  ani_story smallint NOT NULL,
  ani_ero smallint NOT NULL,
  ani_story_sp animation,
  ani_story_cg animation,
  ani_cutscene animation,
  ani_ero_sp animation,
  ani_ero_cg animation,
  ani_bg boolean,
  ani_face boolean,
  has_ero boolean NOT NULL,
  patch boolean NOT NULL,
  freeware boolean NOT NULL,
  uncensored boolean,
  official boolean NOT NULL,
  catalog text NOT NULL,
  notes text NOT NULL,
  engine integer,
  PRIMARY KEY(id)
);

CREATE TABLE releases_drm (
  id text NOT NULL,
  drm integer NOT NULL,
  notes text NOT NULL,
  PRIMARY KEY(id, drm)
);

CREATE TABLE releases_extlinks (
  id text NOT NULL,
  link integer NOT NULL,
  PRIMARY KEY(id, link)
);

CREATE TABLE releases_images (
  id text NOT NULL,
  img text NOT NULL,
  vid text,
  itype release_image_type NOT NULL,
  lang language[],
  PRIMARY KEY(id, img)
);

CREATE TABLE releases_media (
  id text NOT NULL,
  medium medium NOT NULL,
  qty smallint NOT NULL,
  PRIMARY KEY(id, medium, qty)
);

CREATE TABLE releases_platforms (
  id text NOT NULL,
  platform platform NOT NULL,
  PRIMARY KEY(id, platform)
);

CREATE TABLE releases_producers (
  id text NOT NULL,
  pid text NOT NULL,
  developer boolean NOT NULL,
  publisher boolean NOT NULL,
  PRIMARY KEY(id, pid)
);

CREATE TABLE releases_supersedes (
  id text NOT NULL,
  rid text NOT NULL,
  PRIMARY KEY(id, rid)
);

CREATE TABLE releases_titles (
  id text NOT NULL,
  lang language NOT NULL,
  mtl boolean NOT NULL,
  title text,
  latin text,
  PRIMARY KEY(id, lang)
);

CREATE TABLE releases_vn (
  id text NOT NULL,
  vid text NOT NULL,
  rtype release_type NOT NULL,
  PRIMARY KEY(id, vid)
);

CREATE TABLE rlists (
  uid text NOT NULL,
  rid text NOT NULL,
  added date NOT NULL,
  status smallint NOT NULL,
  PRIMARY KEY(uid, rid)
);

CREATE TABLE staff (
  id text NOT NULL,
  gender staff_gender NOT NULL,
  lang language NOT NULL,
  main integer NOT NULL,
  description text NOT NULL,
  prod text,
  PRIMARY KEY(id)
);

CREATE TABLE staff_alias (
  id text NOT NULL,
  aid integer,
  name text NOT NULL,
  latin text,
  PRIMARY KEY(aid)
);

CREATE TABLE staff_extlinks (
  id text NOT NULL,
  link integer NOT NULL,
  PRIMARY KEY(id, link)
);

CREATE TABLE tags (
  id text NOT NULL,
  cat tag_category NOT NULL,
  defaultspoil smallint NOT NULL,
  searchable boolean NOT NULL,
  applicable boolean NOT NULL,
  name text NOT NULL,
  alias text NOT NULL,
  description text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE tags_parents (
  id text NOT NULL,
  parent text NOT NULL,
  main boolean NOT NULL,
  PRIMARY KEY(id, parent)
);

CREATE TABLE tags_vn (
  date date NOT NULL,
  tag text NOT NULL,
  vid text NOT NULL,
  uid text,
  vote smallint NOT NULL,
  spoiler smallint CHECK(spoiler >= 0 AND spoiler <= 2),
  ignore boolean NOT NULL,
  lie boolean,
  notes text NOT NULL
);

CREATE TABLE traits (
  id text NOT NULL,
  gid text,
  gorder smallint NOT NULL,
  defaultspoil smallint NOT NULL,
  sexual boolean NOT NULL,
  searchable boolean NOT NULL,
  applicable boolean NOT NULL,
  name text NOT NULL,
  alias text NOT NULL,
  description text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE traits_parents (
  id text NOT NULL,
  parent text NOT NULL,
  main boolean NOT NULL,
  PRIMARY KEY(id, parent)
);

CREATE TABLE ulist_labels (
  uid text NOT NULL,
  id smallint NOT NULL,
  label text NOT NULL,
  PRIMARY KEY(uid, id)
);

CREATE TABLE ulist_vns (
  uid text NOT NULL,
  vid text NOT NULL,
  added date NOT NULL,
  lastmod date NOT NULL,
  vote_date date,
  started date,
  finished date,
  vote smallint CHECK(vote IS NULL OR vote BETWEEN 10 AND 100),
  notes text NOT NULL,
  labels smallint[] NOT NULL,
  PRIMARY KEY(uid, vid)
);

CREATE TABLE users (
  id text NOT NULL,
  ign_votes boolean NOT NULL,
  perm_imgvote boolean NOT NULL,
  perm_tag boolean NOT NULL,
  perm_lengthvote boolean NOT NULL,
  username text,
  PRIMARY KEY(id)
);

CREATE TABLE vn (
  id text NOT NULL,
  image text,
  c_image text,
  olang language NOT NULL,
  c_votecount integer NOT NULL,
  c_rating smallint,
  c_average smallint,
  c_length smallint,
  c_lengthnum smallint NOT NULL,
  length smallint NOT NULL,
  devstatus smallint NOT NULL,
  alias text NOT NULL,
  description text NOT NULL,
  PRIMARY KEY(id)
);

CREATE TABLE vn_anime (
  id text NOT NULL,
  aid integer NOT NULL,
  PRIMARY KEY(id, aid)
);

CREATE TABLE vn_editions (
  id text NOT NULL,
  lang language,
  eid smallint NOT NULL,
  official boolean NOT NULL,
  name text NOT NULL,
  PRIMARY KEY(id, eid)
);

CREATE TABLE vn_extlinks (
  id text NOT NULL,
  link integer NOT NULL,
  PRIMARY KEY(id, link)
);

CREATE TABLE vn_image_votes (
  vid text NOT NULL,
  uid text NOT NULL,
  img text NOT NULL,
  PRIMARY KEY(vid, uid, img)
);

CREATE TABLE vn_length_votes (
  vid text NOT NULL,
  uid text,
  date date NOT NULL,
  length smallint NOT NULL,
  speed smallint,
  rid text[] NOT NULL,
  notes text NOT NULL,
  lang language[]
);

CREATE TABLE vn_relations (
  id text NOT NULL,
  vid text NOT NULL,
  relation vn_relation NOT NULL,
  official boolean NOT NULL,
  PRIMARY KEY(id, vid)
);

CREATE TABLE vn_screenshots (
  id text NOT NULL,
  scr text NOT NULL,
  rid text,
  PRIMARY KEY(id, scr)
);

CREATE TABLE vn_seiyuu (
  id text NOT NULL,
  cid text NOT NULL,
  aid integer NOT NULL,
  note text NOT NULL,
  PRIMARY KEY(id, aid, cid)
);

CREATE TABLE vn_staff (
  id text NOT NULL,
  aid integer NOT NULL,
  role credit_type NOT NULL,
  eid smallint,
  note text NOT NULL
);

CREATE TABLE vn_titles (
  id text NOT NULL,
  lang language NOT NULL,
  official boolean NOT NULL,
  title text NOT NULL,
  latin text,
  PRIMARY KEY(id, lang)
);

CREATE TABLE wikidata (
  id integer NOT NULL,
  enwiki text,
  jawiki text,
  website text[],
  vndb text[],
  mobygames text[],
  mobygames_company text[],
  gamefaqs_game integer[],
  gamefaqs_company integer[],
  anidb_anime integer[],
  anidb_person integer[],
  ann_anime integer[],
  ann_manga integer[],
  musicbrainz_artist uuid[],
  twitter text[],
  vgmdb_product integer[],
  vgmdb_artist integer[],
  discogs_artist integer[],
  acdb_char integer[],
  acdb_source integer[],
  indiedb_game text[],
  howlongtobeat integer[],
  crunchyroll text[],
  igdb_game text[],
  giantbomb text[],
  pcgamingwiki text[],
  steam integer[],
  gog text[],
  pixiv_user integer[],
  doujinshi_author integer[],
  soundcloud text[],
  humblestore text[],
  itchio text[],
  playstation_jp text[],
  playstation_na text[],
  playstation_eu text[],
  lutris text[],
  wine integer[],
  mobygames_game integer[],
  PRIMARY KEY(id)
);
