create table aid
(
  aid int not null
    primary key,
  tid int null,
  typename varchar(255) null,
  arctype varchar(255) null,
  play int null,
  review int null,
  video_review int null,
  favorites int null,
  title varchar(255) null,
  allow_bp int null,
  allow_feed int null,
  allow_download int null,
  description varchar(500) null,
  tag varchar(255) null,
  pic varchar(255) null,
  author varchar(255) null,
  mid int null,
  face varchar(255) null,
  pages int null,
  instant_server varchar(255) null,
  created int null,
  created_at varchar(255) null,
  credit int null,
  coins int null,
  spid int null,
  src varchar(255) null,
  cid int null,
  partname varchar(255) null,
  offsite varchar(255) null,
  typename2 varchar(255) null,
  partid int null,
  sp_title varchar(255) null,
  season_id int null,
  season_index varchar(255) null,
  season_episode varchar(255) null,
  bangumi_id int null
)
;

create table aidcid
(
  aid int not null,
  cid int not null,
  partid int not null,
  partname varchar(255) null,
  primary key (aid, partid)
)
;

create table avcount
(
  date date not null,
  count int null
)
;

create table avplay
(
  title varchar(255) not null,
  play int(255) null,
  timestamp datetime not null,
  ranking int null,
  primary key (title, timestamp)
)
;

create table baiduyun
(
  id int not null auto_increment
    primary key,
  url varchar(50) null,
  password varchar(4) null,
  `desc` varchar(100) null,
  constraint baiduyun_url_uindex
  unique (url)
)
;

create table bangumi
(
  bangumi_id int not null
    primary key,
  season_id int null,
  title varchar(255) null,
  allow_download varchar(255) null
)
;

create table cid
(
  cid int not null
    primary key,
  maxlimit int null,
  chatid int null,
  server varchar(255) null,
  vtype varchar(255) null,
  oriurl varchar(255) null,
  aid int null,
  typeid int null,
  pid int null,
  click int null,
  favourites int null,
  credits int null,
  coins int null,
  fw_click int(255) null,
  duration varchar(255) null,
  arctype varchar(255) null,
  danmu int null,
  bottom int null,
  sinapi int null,
  acceptguest varchar(255) null,
  acceptaccel varchar(255) null
)
;

create table data
(
  cid int not null
    primary key,
  aid int null,
  dp_done_mp4 tinyint(1) null,
  letv_vu varchar(255) null,
  dp_done_flv tinyint(1) null,
  upload_meta int null,
  type varchar(255) null,
  vp int null,
  upload int null,
  author varchar(255) null,
  cover varchar(255) null,
  title varchar(255) null,
  page int null,
  dispatch int null,
  vid varchar(255) null,
  backup_vid varchar(255) null,
  files int null,
  dispatch_servers int null,
  cache varchar(255) null,
  storage_server int null,
  dp_done tinyint(1) null,
  duration float null,
  mid int null,
  dp_done_hdmp4 tinyint(1) null,
  letv_vid int null,
  storage int null,
  letv_addr varchar(255) null,
  subtitle varchar(255) null
)
;

create table dispatch_servers
(
  is_active int null,
  description varchar(255) null,
  done int null,
  state varchar(255) null,
  done_at datetime null,
  create_at datetime null,
  dms_id int null,
  server int null,
  format varchar(255) null,
  `create` int null,
  cid int not null,
  id int not null,
  primary key (id, cid)
)
;

create table files
(
  filesize mediumtext null,
  `order` int null,
  md5 varchar(255) null,
  path varchar(255) null,
  length int null,
  storage_state int null,
  format varchar(255) null,
  cid int not null,
  id int not null,
  primary key (id, cid)
)
;

create table node_server
(
  sid varchar(255) null,
  server_id varchar(255) null,
  perferred_zones varchar(255) null,
  domain varchar(255) null,
  allow_upload varchar(255) null,
  ip varchar(255) null,
  node_id varchar(255) null,
  cid int not null,
  id int not null,
  primary key (id, cid)
)
;

create table param
(
  `key` varchar(255) not null
    primary key,
  value varchar(1024) null,
  `desc` varchar(255) null
)
;

create table save
(
  id int not null,
  bilibili varchar(20) null,
  lastUpdateTime timestamp null,
  latest tinyint(1) null
)
;

create table testjson
(
  jackson json null
)
;

create table tsdm
(
  animeName varchar(50) not null
    primary key,
  tsdmUrl varchar(512) null,
  playTime date null,
  updateTime varchar(30) null,
  copyright varchar(20) null,
  lastUpdateTime varchar(100) null
)
;

create table upload
(
  encode_server varchar(255) null,
  done int null,
  state varchar(255) null,
  create_at datetime null,
  done_at datetime null,
  uploaded int null,
  `convert` int null,
  error_reason varchar(255) null,
  ip varchar(255) null,
  timestamp int null,
  filename varchar(255) null,
  uploaded_at datetime null,
  convert_at datetime null,
  node_server int null,
  cid int not null
    primary key
)
;

create table upload_meta
(
  storage_server int null,
  done int null,
  done_at datetime null,
  create_at datetime null,
  storage_state int null,
  format varchar(255) null,
  vp int null,
  `create` int null,
  cid int not null,
  id int not null,
  primary key (cid, id)
)
;

create table vstorage
(
  id int not null
    primary key,
  code int null
)
;

create view 番剧 as
  SELECT
    `c`.`aid`      AS `aid`,
    `c`.`cid`      AS `cid`,
    `c`.`pid`      AS `pid`,
    `c`.`typeid`   AS `typeid`,
    `d`.`title`    AS `title`,
    `d`.`subtitle` AS `subtitle`
  FROM (`bilibili`.`cid` `c`
    JOIN `bilibili`.`data` `d` ON (((`c`.`cid` = `d`.`cid`) AND ((`c`.`typeid` = 32) OR (`c`.`typeid` = 33)))));

