m151031_160731_taxonomy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTableOptions() 0 8 2
A up() 0 26 2
A down() 0 5 1
1
<?php
2
3
use nkostadinov\taxonomy\models\TaxonomyDef;
4
use nkostadinov\taxonomy\models\TaxonomyTerms;
5
use yii\db\Migration;
6
7
class m151031_160731_taxonomy extends Migration
8
{
9
    public function getTableOptions()
10
    {
11
        if ($this->db->driverName === 'mysql') {
12
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
13
            return 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
14
        } else
15
            throw new Exception('Unsupported database.');
16
    }
17
18
    public function up()
19
    {
20
        $this->createTable(TaxonomyDef::tableName(), [
21
            'id' => $this->primaryKey(),
22
            'name' => $this->string()->notNull()->unique(),
23
            'class' => $this->string()->notNull(),
24
            'created_at' => $this->timestamp(),
25
            'total_count' => $this->bigInteger()->defaultValue(0),
26
            'data_table' => $this->string()->notNull(),
27
            'ref_table' => $this->string()->notNull(),
28
            'migration' => $this->string()
29
        ], $this->getTableOptions());
30
31
        $this->createTable(TaxonomyTerms::tableName(), [
32
            'id' => $this->bigPrimaryKey(),
33
            'taxonomy_id' => $this->integer()->notNull(),
34
            'term' => $this->string(),
35
            'total_count' => $this->bigInteger()->defaultValue(0),
36
            'parent_id' => $this->bigInteger(),
37
        ], $this->getTableOptions());
38
39
        if ($this->db->driverName === 'mysql') {
40
            $this->addForeignKey('fk_TaxonomyTerm_Taxonomy', TaxonomyTerms::tableName(), 'taxonomy_id',
41
                TaxonomyDef::tableName(), 'id');
42
        }
43
    }
44
45
    public function down()
46
    {
47
        $this->dropTable(TaxonomyTerms::tableName());
48
        $this->dropTable(TaxonomyDef::tableName());
49
    }
50
}
51