<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package fusionLib
 * @copyright Copyright (c) 2013 fusionLib. All rights reserved.
 * @link http://fusionlib.com
 */

/**
 * flCacheDbInstaller Class
 *
 * Class to provide the functionality to install, upgrade and remove the database
 * tables required for the database cache to operate.
 *
 * @package fusionLib
 */
class flCacheDbInstaller extends flDbInstallerInterface {

	/**
	 * Install or upgrade the database.
	 *
	 * @param flDb $db The database object through which to access the database.
	 */
	function install($db) {
		$this->createIfNotExists($db, 'fl_cache', "
CREATE  TABLE IF NOT EXISTS `fl_cache` (
  `id` CHAR(32) NOT NULL ,
  `expireat` INT UNSIGNED NOT NULL ,
  `content` TEXT NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `expireat` (`expireat` ASC) )
ENGINE = MyISAM
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci
");
	}

	/**
	 * Uninstall the database, all data is lost.
	 *
	 * @param flDb $db The database object through which to access the database.
	 */
	function uninstall($db) {
		$db->query('DROP TABLE IF EXISTS `fl_cache`');
	}
}
