<?php
require_once(dirname(__FILE__).'/../../upgrade.php');
class create_subscribers_table extends UPGRADE
{
	/**
	* IsAlreadyUpgraded
	* Do we need to run this classes upgrade script or not ?
	*
	* @return bool true if the upgrade has already run, otherwise false
	*/
	function IsAlreadyUpgraded()
	{
		return $this->TableExists($GLOBALS['tablePrefix'].'subscribers');
	}

	/**
	* Upgrade
	* Do the actual upgrade of this component. If this is successful all
	* subsequent calls to IsAlreadyUpgraded should return true
	*
	* @return void
	*/
	function Upgrade()
	{
		$query = '
			CREATE TABLE `'.$GLOBALS['tablePrefix'].'subscribers` (
				subscriberid int not null auto_increment,
				questionid int not null,
				email varchar(255) not null,
				subscribedate datetime not null,
				confirmed tinyint(1) not null,
				confirmcode varchar(32) not null,
				primary key (subscriberid),
				key `questionid` (questionid),
				key `email_confirmcode` (email, confirmcode),
				unique key `idx_s_questionid_email` (questionid, email)
			)
		';
		$result = $GLOBALS['AKB_DB']->Query($query);
	}

}
?>
