1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/paulzi/yii2-nested-sets |
4
|
|
|
* @copyright Copyright (c) 2015 PaulZi <[email protected]> |
5
|
|
|
* @license MIT (https://github.com/paulzi/yii2-nested-sets/blob/master/LICENSE) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace paulzi\nestedsets\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
|
201 |
|
public function up() |
19
|
|
|
{ |
20
|
201 |
|
ob_start(); |
21
|
201 |
|
$tableOptions = null; |
22
|
201 |
|
if ($this->db->driverName === 'mysql') { |
23
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
24
|
67 |
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
// tree |
28
|
201 |
|
if ($this->db->getTableSchema('{{%tree}}', true) !== null) { |
29
|
197 |
|
$this->dropTable('{{%tree}}'); |
30
|
|
|
} |
31
|
201 |
|
$this->createTable('{{%tree}}', [ |
32
|
201 |
|
'id' => Schema::TYPE_PK, |
33
|
201 |
|
'lft' => Schema::TYPE_INTEGER . ' NOT NULL', |
34
|
201 |
|
'rgt' => Schema::TYPE_INTEGER . ' NOT NULL', |
35
|
201 |
|
'depth' => Schema::TYPE_INTEGER . ' NOT NULL', |
36
|
201 |
|
'slug' => Schema::TYPE_STRING . ' NOT NULL', |
37
|
201 |
|
], $tableOptions); |
38
|
201 |
|
$this->createIndex('lft1', '{{%tree}}', ['lft', 'rgt']); |
39
|
201 |
|
$this->createIndex('rgt1', '{{%tree}}', ['rgt']); |
40
|
|
|
|
41
|
|
|
// multiple tree |
42
|
201 |
|
if ($this->db->getTableSchema('{{%multiple_tree}}', true) !== null) { |
43
|
197 |
|
$this->dropTable('{{%multiple_tree}}'); |
44
|
|
|
} |
45
|
201 |
|
$this->createTable('{{%multiple_tree}}', [ |
46
|
201 |
|
'id' => Schema::TYPE_PK, |
47
|
201 |
|
'tree' => Schema::TYPE_INTEGER . ' NULL', |
48
|
201 |
|
'lft' => Schema::TYPE_INTEGER . ' NOT NULL', |
49
|
201 |
|
'rgt' => Schema::TYPE_INTEGER . ' NOT NULL', |
50
|
201 |
|
'depth' => Schema::TYPE_INTEGER . ' NOT NULL', |
51
|
201 |
|
'slug' => Schema::TYPE_STRING . ' NOT NULL', |
52
|
201 |
|
], $tableOptions); |
53
|
201 |
|
$this->createIndex('lft2', '{{%multiple_tree}}', ['tree', 'lft', 'rgt']); |
54
|
201 |
|
$this->createIndex('rgt2', '{{%multiple_tree}}', ['tree', 'rgt']); |
55
|
|
|
|
56
|
|
|
// update cache (sqlite bug) |
57
|
201 |
|
$this->db->getSchema()->getTableSchema('{{%tree}}', true); |
58
|
201 |
|
$this->db->getSchema()->getTableSchema('{{%multiple_tree}}', true); |
59
|
201 |
|
ob_end_clean(); |
60
|
201 |
|
} |
61
|
|
|
} |
62
|
|
|
|