Blame view

console/migrations/m160325_153328_file_relation_table.php 1.48 KB
3735dff7   Yarik   test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  <?php
  
      use yii\db\Migration;
  
      class m160325_153328_file_relation_table extends Migration
      {
  
          public function up()
          {
              $this->createTable('{{%file_relation}}', [
                  'file_relation_id' => $this->primaryKey(),
                  'file_id'          => $this->integer()
                                             ->notNull(),
                  'model'            => $this->string()
                                             ->notNull(),
                  'model_id'         => $this->integer()
                                             ->notNull(),
                  'user_id'          => $this->integer(),
                  'date_add'         => $this->timestamp()
                                             ->notNull()
                                             ->defaultExpression('NOW()'),
                  'status'           => $this->smallInteger()
                                             ->defaultValue(1),
              ]);
              $this->addForeignKey('file_relation_file', '{{%file_relation}}', 'file_id', '{{%file}}', 'file_id', 'CASCADE', 'CASCADE');
              $this->addForeignKey('file_relation_user', '{{%file_relation}}', 'user_id', '{{%user}}', 'id', 'SET NULL', 'CASCADE');
          }
  
          public function down()
          {
              $this->dropForeignKey('file_relation_file', '{{%file_relation}}');
              $this->dropForeignKey('file_relation_user', '{{%file_relation}}');
              $this->dropTable('{{%file_relation}}');
          }
      }