TestMigration   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 62
ccs 45
cts 45
cp 1
rs 10
c 0
b 0
f 0

1 Method

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