Blame view

migrations/m161101_144434_blog_article_to_product.php 1.93 KB
3b1725bf   Alexey Boroda   -Bug with fill re...
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  <?php
      
      use yii\db\Migration;
      
      class m161101_144434_blog_article_to_product extends Migration
      {
          public function up()
          {
              /**
               * Creates junction table and all stuff for adding related products to articles
               */
              $this->createTable(
                  'blog_article_to_product',
                  [
                      'id'              => $this->primaryKey(),
                      'blog_article_id' => $this->integer()
                                                ->notNull(),
                      'product_id'      => $this->integer()
                                                ->notNull(),
                  ]
              );
              
              $this->createIndex(
                  'blog_article_to_product_uk',
                  'blog_article_to_product',
                  [
                      'blog_article_id',
                      'product_id',
                  ],
                  true
              );
              
              $this->addForeignKey(
                  'blog_article_to_product_art_fk',
                  'blog_article_to_product',
                  'blog_article_id',
                  'blog_article',
                  'id',
                  'CASCADE',
                  'CASCADE'
              );
              
              $this->addForeignKey(
                  'blog_article_to_product_prod_fk',
                  'blog_article_to_product',
                  'product_id',
                  'product',
                  'id',
                  'CASCADE',
                  'CASCADE'
              );
          }
          
          public function down()
          {
              $this->dropForeignKey('blog_article_to_product_prod_fk', 'blog_article_to_product');
              $this->dropForeignKey('blog_article_to_product_art_fk', 'blog_article_to_product');
              $this->dropIndex('blog_article_to_product_uk', 'blog_article_to_product');
              $this->dropTable('blog_article_to_product');
          }
      }