1 | <?php |
||
18 | class m150909_153426_cache_init extends Migration |
||
19 | { |
||
20 | /** |
||
21 | * @throws yii\base\InvalidConfigException |
||
22 | * @return DbCache |
||
23 | */ |
||
24 | protected function getCache() |
||
25 | { |
||
26 | $cache = Yii::$app->getCache(); |
||
27 | if (!$cache instanceof DbCache) { |
||
28 | throw new InvalidConfigException('You should configure "cache" component to use database before executing this migration.'); |
||
29 | } |
||
30 | |||
31 | return $cache; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | public function up() |
||
38 | { |
||
39 | $cache = $this->getCache(); |
||
40 | $this->db = $cache->db; |
||
41 | |||
42 | $tableOptions = null; |
||
43 | if ($this->db->driverName === 'mysql') { |
||
44 | // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
||
45 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
||
46 | } |
||
47 | |||
48 | $this->createTable($cache->cacheTable, [ |
||
49 | 'id' => $this->string(128)->notNull(), |
||
50 | 'expire' => $this->integer(), |
||
51 | 'data' => $this->binary(), |
||
52 | 'PRIMARY KEY ([[id]])', |
||
53 | ], $tableOptions); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function down() |
||
65 | } |
||
66 | } |
||
67 |