Blame view

migrations/m170503_141942_create_payment_table.php 2.27 KB
11ecfb79   Yarik   Basket
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  <?php
      
      use yii\db\Migration;
      
      /**
       * Handles the creation of table `payment`.
       */
      class m170503_141942_create_payment_table extends Migration
      {
          /**
           * @inheritdoc
           */
          public function up()
          {
              $this->createTable(
                  'payment',
                  [
                      'id'     => $this->primaryKey(),
                      'sort'   => $this->integer()
                                       ->defaultValue(0),
                      'status' => $this->boolean()
                                       ->defaultValue(true),
                  ]
              );
              
              $this->createTable(
                  'payment_lang',
                  [
                      'payment_id'  => $this->integer()
                                            ->notNull(),
                      'language_id' => $this->integer()
                                            ->notNull(),
                      'title'       => $this->string()
                                            ->notNull(),
                      'description' => $this->text(),
                  ]
              );
              
              $this->addPrimaryKey(
                  'payment_lang_pkey',
                  'payment_lang',
                  [
                      'payment_id',
                      'language_id',
                  ]
              );
              
              $this->addForeignKey(
                  'payment_lang_payment_id_fkey',
                  'payment_lang',
                  'payment_id',
                  'payment',
                  'id',
                  'CASCADE',
                  'CASCADE'
              );
              $this->addForeignKey(
                  'payment_lang_language_id_fkey',
                  'payment_lang',
                  'language_id',
                  'language',
                  'id',
                  'RESTRICT',
                  'CASCADE'
              );
          }
          
          /**
           * @inheritdoc
           */
          public function down()
          {
              $this->dropForeignKey('payment_lang_payment_id_fkey', 'payment_lang');
              $this->dropForeignKey('payment_lang_language_id_fkey', 'payment_lang');
              
              $this->dropTable('payment_lang');
              
              $this->dropTable('payment');
          }
      }