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
|
|
|
|