DROP TABLE IF EXISTS `tvrageepisodes`;
CREATE TABLE `episodeinfo` (
  `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `rageID` int(11) unsigned NOT NULL,
  `tvdbID` INT(11) UNSIGNED NULL,
  `imdbID` MEDIUMINT(7) UNSIGNED ZEROFILL NULL,
  `showtitle` VARCHAR(255) NULL,
  `airdate` datetime NOT NULL,
  `link` varchar(255) NULL,
  `fullep` varchar(20) NOT NULL,
  `eptitle` varchar(255) NULL,
  `director` VARCHAR(255) NULL,
  `gueststars` VARCHAR(1024) NULL,
  `overview` VARCHAR(10000) NULL,
  `rating` FLOAT(4) NULL,
  `writer` VARCHAR(255) NULL,
  `epabsolute` INT(6) NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `fullep` (`showtitle`, `fullep`)
) ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci AUTO_INCREMENT=1 ;

CREATE INDEX ix_episodeinfo_rageID ON episodeinfo (rageID);
CREATE INDEX ix_episodeinfo_tvdbID ON episodeinfo (tvdbID);
CREATE INDEX ix_episodeinfo_imdbID ON episodeinfo (imdbID);

CREATE TABLE `thetvdb`
(
  `ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `tvdbID` INT(11) UNSIGNED NOT NULL,
  `actors` VARCHAR(1024) NULL,
  `airsday` VARCHAR(9) NULL,
  `airstime` TIME NULL,
  `contentrating` VARCHAR(4) NULL,
  `firstaired` DATE NOT NULL,
  `genre` VARCHAR(255) NULL,
  `imdbID` MEDIUMINT(7) UNSIGNED ZEROFILL NULL,
  `network` VARCHAR(50) NULL,
  `overview` VARCHAR(10000) NULL,
  `rating` FLOAT(4) NULL,
  `ratingcount` INT(10) NULL,
  `runtime` INT(5) NULL,
  `seriesname` VARCHAR(255) NOT NULL,
  `status` VARCHAR(50) NULL,
  `lastupdated` INT(12) NULL,
  `createddate` DATETIME NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci AUTO_INCREMENT=1 ;

ALTER TABLE releases ADD `tvdbID` INT(11) UNSIGNED NULL AFTER `rageID`;
ALTER TABLE releases ADD `episodeinfoID` INT NULL AFTER `imdbID`;
INSERT INTO site (`setting`, `value`, `updateddate` )
VALUES ('lookupthetvdb', '1', now());