m141208_045658_create_question_table::safeUp()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 20
c 1
b 0
f 0
rs 9.7666
cc 2
nc 2
nop 0
1
<?php
2
3
use yii\db\Schema;
4
use yii\db\Migration;
5
6
class m141208_045658_create_question_table extends Migration
7
{
8
    public function safeUp()
9
    {
10
        $tableOptions = null;
11
        if ($this->db->driverName === 'mysql') {
12
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
13
        }
14
15
        $this->createTable("question", [
16
            "id" => Schema::TYPE_PK,
17
            "user_id" => Schema::TYPE_INTEGER . " NOT NULL",
18
            "option_id" => Schema::TYPE_INTEGER . " NOT NULL",
19
            "user_option_id" => Schema::TYPE_INTEGER . " NOT NULL",
20
            "question" => Schema::TYPE_INTEGER . " NOT NULL",
21
            "answer" => Schema::TYPE_TEXT . " NOT NULL",
22
            "date" => Schema::TYPE_DATETIME . " NOT NULL"
23
        ], $tableOptions);
24
25
        $this->addForeignKey('question_user_fk', '{{%question}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'CASCADE');
26
        $this->addForeignKey('question_option_fk', '{{%question}}', 'option_id', '{{%option}}', 'id', 'CASCADE', 'CASCADE');
27
        $this->addForeignKey('question_user_option_fk', '{{%question}}', 'user_option_id', '{{%user_option_link}}', 'id', 'CASCADE', 'CASCADE');
28
29
    }
30
31
    public function safeDown()
32
    {
33
        $this->dropForeignKey("question_user_fk", "{{%question}}");
34
        $this->dropForeignKey("question_option_fk", "{{%question}}");
35
        $this->dropForeignKey("question_user_option_fk", "{{%question}}");
36
        $this->dropTable("question");
37
    }
38
}
39