Blame view

console/migrations/m160321_232402_orders.php 1.83 KB
cea5c45d   Administrator   21.03.16 Versrka
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  <?php
  
  use yii\db\Migration;
  
  class m160321_232402_orders extends Migration
  {
      public function up()
      {
          $tableOptions = null;
          if ($this->db->driverName === 'mysql') {
              // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
              $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
          }
  
          $this->createTable('{{%orders}}', [
f7aa643c   Administrator   21.03.16 Versrka
16
17
              'order_id' => $this->primaryKey(),
              'customer_id' => $this->integer(),
cea5c45d   Administrator   21.03.16 Versrka
18
19
20
21
22
23
24
25
26
27
              'name' => $this->string()->notNull(),
              'email' => $this->string()->notNull(),
              'phone' => $this->string(32)->notNull(),
              'delivery' => $this->integer(),
              'payment' => $this->integer(),
              'code' => $this->string(),
              'status' => $this->smallInteger(),
              'created_at' => $this->integer()->notNull(),
              'updated_at' => $this->integer()->notNull(),
          ], $tableOptions);
f7aa643c   Administrator   21.03.16 Versrka
28
29
30
31
32
33
34
35
36
37
38
  
          $this->createTable('{{%order_items}}', [
              'order_items_id' => $this->primaryKey(),
              'order_id' => $this->integer(),
              'item_id' => $this->integer(),
              'item_count' => $this->integer(),
              'price' => $this->float(),
          ], $tableOptions);
  
          $this->addForeignKey('orders_items_fk', '{{%order_items}}', 'order_id', '{{%orders}}', 'order_id', 'CASCADE', 'CASCADE');
          $this->addForeignKey('orders_items_items_fk', '{{%order_items}}', 'item_id', '{{%product}}', 'product_id', 'RESTRICT', 'RESTRICT');
cea5c45d   Administrator   21.03.16 Versrka
39
40
41
42
      }
  
      public function down()
      {
f7aa643c   Administrator   21.03.16 Versrka
43
44
          $this->dropForeignKey('orders_items_fk', '{{%order_items}}');
          $this->dropForeignKey('orders_items_items_fk', '{{%order_items}}');
cea5c45d   Administrator   21.03.16 Versrka
45
          $this->dropTable('{{%orders}}');
f7aa643c   Administrator   21.03.16 Versrka
46
          $this->dropTable('{{%order_items}}');
cea5c45d   Administrator   21.03.16 Versrka
47
48
49
      }
  
  }