· 8 years ago · Feb 06, 2018, 08:04 AM
1$subQuery = '';
2
3 if ($this->isLiveBuild) {
4 $partitions = [];
5 $date = \DateTime::createFromFormat('Ymd', date('Ymd'));
6 for ($i = 0; $i < 5; $i++) {
7 $partitionName = $date->format('YW');
8 $date->modify("+1 week");
9 $weekYear = $date->format('YW');
10 $partitions[] = "PARTITION p" . $partitionName . " VALUES LESS THAN (" . $weekYear . ") ENGINE = InnoDB";
11 }
12 $subQuery = "/*!50100 PARTITION BY RANGE (YEARWEEK(date))
13 (" . implode(",\n", $partitions) . ") */";
14 }
15
16 $sql = "
17 CREATE TABLE IF NOT EXISTS {$this->tableName} (
18 id binary(32) NOT NULL,
19 date date NOT NULL default '0000-00-00',
20 action smallint(5) unsigned NOT NULL DEFAULT 1,
21 campaign mediumint(8) unsigned NOT NULL DEFAULT '0',
22 site mediumint(8) unsigned NOT NULL DEFAULT '0',
23 country char(3) NOT NULL DEFAULT '',
24 server mediumint(8) unsigned NOT NULL DEFAULT '0',
25 emailServiceProvider smallint(5) unsigned NOT NULL DEFAULT '0',
26 platform tinyint(3) unsigned NOT NULL DEFAULT '0',
27 source tinyint(3) unsigned NOT NULL DEFAULT '0',
28 actionWay tinyint(3) unsigned NOT NULL DEFAULT '0',
29 gender enum('male', 'female','undefined') NOT NULL DEFAULT 'undefined',
30 messageId int(10) unsigned NOT NULL DEFAULT 0,
31 messageCaseId int(10) unsigned NOT NULL DEFAULT 0,
32 subjectId int(10) unsigned NOT NULL DEFAULT 0,
33 fromNameId int(10) unsigned NOT NULL DEFAULT 0,
34 contentId int(10) unsigned NOT NULL DEFAULT 0,
35 compositeBinId binary(16) NOT NULL DEFAULT 0,
36 amount int(10) unsigned NOT NULL DEFAULT 1,
37 PRIMARY KEY (date, id),
38 KEY (date,action)
39 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
40 {$subQuery}
41 ";
42 /* example $subQuery
43 (
44 PARTITION p201709 VALUES LESS THAN (201710) ENGINE = InnoDB,
45 PARTITION p201710 VALUES LESS THAN (201711) ENGINE = InnoDB,
46 PARTITION p201711 VALUES LESS THAN (201712) ENGINE = InnoDB,
47 PARTITION p201712 VALUES LESS THAN (201713) ENGINE = InnoDB,
48 PARTITION p201713 VALUES LESS THAN (201714) ENGINE = InnoDB
49 )
50
51 */
52
53 $this->execute($sql);
54
55 return true;
56 }