Blame view

console/migrations/m160516_222821_orders.php 2.66 KB
4253cbec   root   first commit
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
  <?php
  
  use yii\db\Migration;
  
  class m160516_222821_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}}', [
              'id' => $this->primaryKey(),
              'user_id' => $this->integer(),
              'name' => $this->string()->notNull(),
              'surname' => $this->string()->notNull(),
              'patronymic' => $this->string()->notNull(),
              'phone' => $this->string(),
              'phone2' => $this->string(),
              'email' => $this->string(),
              'adress' => $this->string(),
              'body' => $this->text(),
              'total' => $this->float(),
              'date_time' => $this->dateTime(),
              'date_dedline' => $this->date(),
              'reserve' => $this->string(),
              'status' => $this->string(),
              'comment' => $this->text(),
              'label' => $this->integer(),
              'pay' => $this->integer(),
              'numbercard' => $this->integer(),
              'delivery' => $this->string(),
              'declaration' => $this->string(),
              'stock' => $this->string(),
              'consignment' => $this->string(),
              'payment' => $this->string(),
              'insurance' => $this->string(),
              'amount_imposed' => $this->float(),
              'shipping_by' => $this->string(),
              'city' => $this->string(),
          ], $tableOptions);
  
  
          $this->createTable('{{%orders_products}}', [
              'id' => $this->primaryKey(),
              'order_id' => $this->integer(),
              'mod_id' => $this->integer(),
              'product_name' => $this->string(),
              'name' => $this->string(),
              'sku' => $this->string(),
              'price' => $this->float(),
              'count' => $this->integer(),
              'sum_cost' => $this->float(),
          ], $tableOptions);
  
          $this->addForeignKey('orders_products_fk', '{{%orders_products}}', 'order_id', '{{%orders}}', 'id', 'CASCADE', 'CASCADE');
          $this->addForeignKey('orders_products_items_fk', '{{%orders_products}}', 'id', '{{%product}}', 'product_id', 'RESTRICT', 'RESTRICT');
      }
  
      public function down()
      {
          $this->dropForeignKey('orders_products_fk', '{{%orders_products}}');
          $this->dropForeignKey('orders_products_items_fk', '{{%orders_products}}');
          $this->dropTable('{{%orders}}');
          $this->dropTable('{{%orders_products}}');
      }
  
  }