1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/paulzi/yii2-auto-tree |
4
|
|
|
* @copyright Copyright (c) 2015 PaulZi <[email protected]> |
5
|
|
|
* @license MIT (https://github.com/paulzi/yii2-auto-tree/blob/master/LICENSE) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace paulzi\autotree\tests\migrations; |
9
|
|
|
|
10
|
|
|
use yii\db\Schema; |
11
|
|
|
use yii\db\Migration; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author PaulZi <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class TestMigration extends Migration |
17
|
|
|
{ |
18
|
63 |
|
public function up() |
19
|
|
|
{ |
20
|
63 |
|
ob_start(); |
21
|
63 |
|
$tableOptions = null; |
22
|
63 |
|
if ($this->db->driverName === 'mysql') { |
23
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
24
|
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
25
|
|
|
} |
26
|
|
|
|
27
|
63 |
|
if ($this->db->getTableSchema('{{%tree}}', true) !== null) { |
28
|
60 |
|
$this->dropTable('{{%tree}}'); |
29
|
|
|
} |
30
|
63 |
|
$this->createTable('{{%tree}}', [ |
31
|
63 |
|
'id' => Schema::TYPE_PK, |
32
|
63 |
|
'parent_id' => Schema::TYPE_INTEGER . ' NULL', |
33
|
63 |
|
'sort' => Schema::TYPE_INTEGER . ' NULL', |
34
|
63 |
|
'tree' => Schema::TYPE_INTEGER . ' NULL', |
35
|
63 |
|
'lft' => Schema::TYPE_INTEGER . ' NULL', |
36
|
63 |
|
'rgt' => Schema::TYPE_INTEGER . ' NULL', |
37
|
63 |
|
'depth' => Schema::TYPE_INTEGER . ' NULL', |
38
|
63 |
|
'path' => Schema::TYPE_STRING . ' NULL', |
39
|
63 |
|
'slug' => Schema::TYPE_STRING . ' NOT NULL', |
40
|
63 |
|
], $tableOptions); |
41
|
63 |
|
$this->createIndex('parent_sort', '{{%tree}}', ['parent_id', 'sort']); |
42
|
63 |
|
$this->createIndex('lft', '{{%tree}}', ['tree', 'lft', 'rgt']); |
43
|
63 |
|
$this->createIndex('rgt', '{{%tree}}', ['tree', 'rgt']); |
44
|
63 |
|
$this->createIndex('path', '{{%tree}}', ['tree', 'path']); |
45
|
|
|
|
46
|
|
|
// update cache (sqlite bug) |
47
|
63 |
|
$this->db->getSchema()->getTableSchema('{{%tree}}', true); |
48
|
63 |
|
ob_end_clean(); |
49
|
63 |
|
} |
50
|
|
|
} |
51
|
|
|
|