setYear($min, $max); } $tables = $part->getKnownTables(); foreach ($table as $t) { $part->partition($t); } */ /** * Partition Maker * * Helper Tool */ class DBPartitionMaker { private $sqlPart = ''; private $sqlRange = ''; private $yearMin = 2010; private $yearMax = 2020; private $knownTables = array(); public function __construct() { $this->knownTables[] = 'forwardtracking'; $this->knownTables[] = 'cookiepreferences'; $this->knownTables[] = 'sessionview'; $this->knownTables[] = 'pageview'; $this->knownTables[] = 'genericview'; $this->yearMax = date('Y'); $this->sqlRange = ' PARTITION p%d VALUES LESS THAN (%d)'; $this->sqlPart = <<knownTables; } /** * Set Year * * @param int start year * @param int end year */ public function setYear($min, $max = null) { $this->yearMin = $min; if (empty($max)) { return; } $this->yearMax = $max; } /** * Build Parttions SQL * * @return string */ public function partition($table) { $range = array(); for ($i = $this->yearMin; $i <= $this->yearMax; ++$i) { $range[] = sprintf($this->sqlRange, $i, $i + 1); } $range = implode(",\n", $range); return sprintf($this->sqlPart . "\n", $table, $range); } }