Blame view

migrations/m161101_142752_blog_article_lang.php 2.47 KB
3b1725bf   Alexey Boroda   -Bug with fill re...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  <?php
      
      use yii\db\Migration;
      
      class m161101_142752_blog_article_lang extends Migration
      {
          public function up()
          {
              /**
               * Create table with language fields of blog articles
               */
              $this->createTable(
                  'blog_article_lang',
                  [
ba196ec2   Alexey Boroda   -Blog in process
15
16
                      'id'              => $this->primaryKey(),
                      'blog_article_id' => $this->integer()
3b1725bf   Alexey Boroda   -Bug with fill re...
17
                                                 ->notNull(),
ba196ec2   Alexey Boroda   -Blog in process
18
19
20
21
22
23
                      'language_id'     => $this->integer()
                                                ->notNull(),
                      'title'           => $this->string(255),
                      'body'            => $this->text(),
                      'body_preview'    => $this->text(),
                      'alias_id'        => $this->integer(),
3b1725bf   Alexey Boroda   -Bug with fill re...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
                  ]
              );
              
              /**
               * Creating indexes for unique fields (field pairs)
               */
              $this->createIndex(
                  'blog_article_lang_uk',
                  'blog_article_lang',
                  [
                      'blog_article_id',
                      'language_id',
                  ],
                  true
              );
              
              $this->createIndex(
                  'blog_article_alias_uk',
                  'blog_article_lang',
ba196ec2   Alexey Boroda   -Blog in process
43
                  'alias_id',
3b1725bf   Alexey Boroda   -Bug with fill re...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
                  true
              );
              
              /**
               * Add foreign keys in blog_articles and language tables
               */
              $this->addForeignKey(
                  'blog_article_fk',
                  'blog_article_lang',
                  'blog_article_id',
                  'blog_article',
                  'id',
                  'CASCADE',
                  'CASCADE'
              );
              
              $this->addForeignKey(
                  'blog_article_lang_fk',
                  'blog_article_lang',
                  'language_id',
                  'language',
                  'id',
                  'RESTRICT',
                  'CASCADE'
              );
          }
          
          public function down()
          {
              $this->dropForeignKey('blog_article_lang_fk', 'blog_article_lang');
              $this->dropForeignKey('blog_article_fk', 'blog_article_lang');
              $this->dropIndex('blog_article_alias_uk', 'blog_article_lang');
              $this->dropIndex('blog_article_lang_uk', 'blog_article_lang');
              $this->dropTable('blog_article_lang');
          }
      }