SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

CREATE TABLE IF NOT EXISTS `cache_asset` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `latest_version` INT(11) NOT NULL DEFAULT 0,
  `filename` VARCHAR(255) NOT NULL,
  `path` VARCHAR(255) NULL DEFAULT NULL,
  `include_theme` TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'Prepend the path with the dynamic theme dir',
  PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE IF NOT EXISTS `cache_history` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `cache_asset_id` INT(11) NOT NULL,
  `site_id` INT(11) NOT NULL,
  `user_id` INT(11) NOT NULL,
  `bust_when` DATETIME NOT NULL,
  `version` INT(11) NOT NULL DEFAULT 0,
  `reason` TEXT NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_cache_bust_cache_asset1_idx` (`cache_asset_id` ASC),
  INDEX `fk_cache_bust_site1_idx` (`site_id` ASC),
  INDEX `fk_cache_bust_user1_idx` (`user_id` ASC),
  CONSTRAINT `fk_cache_bust_cache_asset1`
    FOREIGN KEY (`cache_asset_id`)
    REFERENCES `cache_asset` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_cache_bust_site1`
    FOREIGN KEY (`site_id`)
    REFERENCES `site` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_cache_bust_user1`
    FOREIGN KEY (`user_id`)
    REFERENCES `user` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;