m170503_141153_create_order_table.php 1.63 KB
<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation of table `order`.
     */
    class m170503_141153_create_order_table extends Migration
    {
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable(
                'order',
                [
                    'id'          => $this->primaryKey(),
                    'user_id'     => $this->integer(),
                    'name'        => $this->string(),
                    'phone'       => $this->string(),
                    'email'       => $this->string(),
                    'city'        => $this->string(),
                    'address'     => $this->string(),
                    'comment'     => $this->string(),
                    'label_id'    => $this->integer()
                                          ->notNull(),
                    'delivery_id' => $this->integer()
                                          ->notNull(),
                    'payment_id'  => $this->integer()
                                          ->notNull(),
                    'created_at'  => $this->integer(),
                    'updated_at'  => $this->integer(),
                    'deleted_at'  => $this->integer(),
                ]
            );
            
            $this->addForeignKey('order_user_id_fkey', 'order', 'user_id', 'customer', 'id', 'RESTRICT', 'CASCADE');
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropForeignKey('order_user_id_fkey', 'order');
            
            $this->dropTable('order');
        }
    }